您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2025/8/14 20:11:15发布35次查看
最近在做天地图是gis集成要输出html到javascript里面涉及到代码转义什么的比较麻烦所以写个php的function
分享一下:
代码如下:
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)
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product