最近在做天地圖是GIS集成··要輸出HTML到JavaScript里面··涉及到代碼轉義什么的比較麻煩··所以寫個PHP的function
分享一下:
function jsformat($str)
{
$str = trim($str);
$str = str_replace('ss', '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)