PHP中输出转义JavaScript代码的实现代码
时间:2021-07-15 09:31:37|栏目:PHP代码|点击: 次
分享一下:
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)
复制代码 代码如下:
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)
上一篇:PHP实现图片自动清理的方法
栏 目:PHP代码
本文标题:PHP中输出转义JavaScript代码的实现代码
本文地址:http://www.codeinn.net/misctech/157650.html






