PHP头条
热点:

用PHP输出转义JavaScript代码


最近在做天地图是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)

www.phpzy.comtrue/php/12453.htmlTechArticle用PHP输出转义JavaScript代码 最近在做天地图是GIS集成要输出HTML到JavaScript里面涉及到代码转义什么的比较麻烦所以写个PHP的function 分享一下: function jsformat($str) { $str = trim($str); $str = str...

相关文章

相关频道:

PHP之友评论

今天推荐