使用php转义输出HTML到JavaScript
本文给大家分享的是个人项目中的一个小需求,需要使用php转义输出HTML到JavaScript,就写了个function,推荐给大家,希望大家能够喜欢。
最近在做天地图是GIS集成··要输出HTML到JavaScript里面··涉及到代码转义什么的比较麻烦··所以写个PHP的function
分享一下:
?
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; } |
使用就不用说了··就是直接调用jsformat($str)
以上所述就是本文的全部内容了,希望能对大家理解php转义到javascript有所帮助

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools