Use php escape to output HTML to JavaScript. Using php escape to output HTML to JavaScript this article shares with you a small demand in your project. you need to use php escape to output HTML to JavaScript and then write a function, we recommend that you use php escape to output HTML to JavaScript.
This article shares with you a small demand in personal projects. you need to use php escape to output HTML to JavaScript, and then write a function. we recommend it to you and hope you like it.
Recently, Map World is integrated with GIS. HTML must be output to JavaScript. code escaping is troublesome. so, write a PHP function.
Share:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 |
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.
This article shares with you a small demand in personal projects. you need to use php escape to output HTML to JavaScript, and then write a function, which is recommended to large ones...