Output HTML to JavaScript using php escape, escape javascript
Recently, map world is integrated with GIS. HTML must be output to JavaScript. Code escaping is troublesome. So, write a PHP function.
Share:
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 ;}
You don't need to use it. · call jsformat ($ str) directly)
The above is all the content of this article. I hope it will help you understand php escaping to javascript.
Please take a moment to share your article with your friends or leave a comment. Thank you for your support!