Heim  >  Artikel  >  Backend-Entwicklung  >  使用php转义输出HTML到JavaScript,转义javascript_PHP教程

使用php转义输出HTML到JavaScript,转义javascript_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:00:07923Durchsuche

使用php转义输出HTML到JavaScript,转义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)

以上所述就是本文的全部内容了,希望能对大家理解php转义到javascript有所帮助

请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/974663.htmlTechArticle使用php转义输出HTML到JavaScript,转义javascript 最近在做天地图是GIS集成··要输出HTML到JavaScript里面··涉及到代码转义什么的比较麻烦··所以...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn