最近在做天地图是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)
http://www.bkjia.com/phpjc/364759.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/364759.htmltecharticle最近在做天地图是gis集成要输出html到javascript里面涉及到代码转义什么的比较麻烦所以写个php的function 分享一下: function jsformat($str) { $str...
