首页 > 开发 > PHP > 正文

PHP中输出转义JavaScript代码的实现代码

2024-05-04 22:07:39
字体:
来源:转载
供稿:网友
分享一下:
代码如下:
function jsformat($str)
{
$str = trim($str);
$str = str_replace('//s//s', '//s', $str);
$str = str_replace(chr(10), '', $str);
$str = str_replace(chr(13), '', $str);
$str = str_replace(' ', '', $str);
$str = str_replace('//', '////', $str);
$str = str_replace('"', '//"', $str);
$str = str_replace('///'', '/////'', $str);
$str = str_replace("'", "/'", $str);
return $str;
}

使用就不用说了,就是直接调用jsformat($str)
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表