escape,encodeURI,encodeURIComponent, URLEncode, RawURLEncode, HTMLEntity, AddSlash, JSON Encode(示例代码

Posted 世有因果知因求果

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了escape,encodeURI,encodeURIComponent, URLEncode, RawURLEncode, HTMLEntity, AddSlash, JSON Encode(示例代码相关的知识,希望对你有一定的参考价值。

online tooling: http://www.the-art-of-web.com/javascript/escape/ 

input : {user:{id:59,innerhtml:"<div>content of inner html</div>"}, data: [1,2,5]}

1. JSON ENCODE:  "{user:{id:59,innerhtml:\"<div>content of inner html<\/div>\"}, data: [1,2,5]}"

2. escape:

%7Buser%3A%7Bid%3A59%2Cinnerhtml%3A%22%3Cdiv%3Econtent%20of%20inner%20html%3C/div%3E%22%7D%2C%20data%3A%20%5B1%2C2%2C5%5D%7D

3. encodeURI:

%7Buser:%7Bid:59,innerhtml:%22%3Cdiv%3Econtent%20of%20inner%20html%3C/div%3E%22%7D,%20data:%20%5B1,2,5%5D%7D

4. EncodeURIComponent:

%7Buser%3A%7Bid%3A59%2Cinnerhtml%3A%22%3Cdiv%3Econtent%20of%20inner%20html%3C%2Fdiv%3E%22%7D%2C%20data%3A%20%5B1%2C2%2C5%5D%7D

5. URL Encode: php function:urlencode

%7Buser%3A%7Bid%3A59%2Cinnerhtml%3A%22%3Cdiv%3Econtent+of+inner+html%3C%2Fdiv%3E%22%7D%2C+data%3A+%5B1%2C2%2C5%5D%7D

6. Raw URL Encode: PHP function:rawurlencode

%7Buser%3A%7Bid%3A59%2Cinnerhtml%3A%22%3Cdiv%3Econtent%20of%20inner%20html%3C%2Fdiv%3E%22%7D%2C%20data%3A%20%5B1%2C2%2C5%5D%7D

7. HTML Entities: PHP function:htmlentities

{user:{id:59,innerhtml:&quot;&lt;div&gt;content of inner html&lt;/div&gt;&quot;}, data: [1,2,5]}

8. Add Slashes: PHP function:addslashes

{user:{id:59,innerhtml:\"<div>content of inner html</div>\"}, data: [1,2,5]}

9.  UTF8 Encode: PHP function:utf8_encode

{user:{id:59,innerhtml:"<div>content of inner html</div>"}, data: [1,2,5]}

10. JSON.stringify()

"{"user":{"id":59,"innerhtml":"<div>content of inner html</div>"},"data":[1,2,5]}"

input: "{"user":{"id":59,"innerhtml":"<div>content of inner html</div>"},"data":[1,2,5]}"

escape:

%22%7B%22user%22%3A%7B%22id%22%3A59%2C%22innerhtml%22%3A%22%3Cdiv%3Econtent%20of%20inner%20html%3C/div%3E%22%7D%2C%22data%22%3A%5B1%2C2%2C5%5D%7D%22

encodeURI:

%22%7B%22user%22:%7B%22id%22:59,%22innerhtml%22:%22%3Cdiv%3Econtent%20of%20inner%20html%3C/div%3E%22%7D,%22data%22:%5B1,2,5%5D%7D%22

encodeURIComponent:

%22%7B%22user%22%3A%7B%22id%22%3A59%2C%22innerhtml%22%3A%22%3Cdiv%3Econtent%20of%20inner%20html%3C%2Fdiv%3E%22%7D%2C%22data%22%3A%5B1%2C2%2C5%5D%7D%22

URLEncode:

%22%7B%22user%22%3A%7B%22id%22%3A59%2C%22innerhtml%22%3A%22%3Cdiv%3Econtent+of+inner+html%3C%2Fdiv%3E%22%7D%2C%22data%22%3A%5B1%2C2%2C5%5D%7D%22

Raw URL Encode:

%22%7B%22user%22%3A%7B%22id%22%3A59%2C%22innerhtml%22%3A%22%3Cdiv%3Econtent%20of%20inner%20html%3C%2Fdiv%3E%22%7D%2C%22data%22%3A%5B1%2C2%2C5%5D%7D%22

HTML Entities:

&quot;{&quot;user&quot;:{&quot;id&quot;:59,&quot;innerhtml&quot;:&quot;&lt;div&gt;content of inner html&lt;/div&gt;&quot;},&quot;data&quot;:[1,2,5]}&quot;

AddSlashes:

\"{\"user\":{\"id\":59,\"innerhtml\":\"<div>content of inner html</div>\"},\"data\":[1,2,5]}\"

JSON Encode:

"\"{\"user\":{\"id\":59,\"innerhtml\":\"<div>content of inner html<\/div>\"},\"data\":[1,2,5]}\""

 

以上是关于escape,encodeURI,encodeURIComponent, URLEncode, RawURLEncode, HTMLEntity, AddSlash, JSON Encode(示例代码的主要内容,如果未能解决你的问题,请参考以下文章

escape()encodeURI()encodeURIComponent() 编码解码

escape,encodeURI,encodeURIComponent

escape()encodeURI()encodeURIComponent()区别详解

js的escape()encodeURI()encodeURIComponent()区别详解

escape()encodeURI()encodeURIComponent()区别详解

escape,encodeURI,encodeURIComponent的区别