{"id":159,"date":"2023-02-18T21:21:41","date_gmt":"2023-02-18T13:21:41","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=159"},"modified":"2023-02-18T21:23:59","modified_gmt":"2023-02-18T13:23:59","slug":"php-json-encode-not-automatically-escape-the-slash","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/18\/php-json-encode-not-automatically-escape-the-slash\/","title":{"rendered":"PHP\u4e2d\u8ba9json_encode\u4e0d\u81ea\u52a8\u8f6c\u4e49\u659c\u6760\u201c\/\u201d\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0bPHP\u4f7f\u7528 json_encode \u5bf9\u6570\u7ec4\u8fdb\u884c json\u683c\u5f0f\u8f6c\u6362\u65f6\u4f1a\u81ea\u52a8\u5c06\u6570\u636e\u4e2d\u542b\u6709\u659c\u6760\u7684\u5b57\u7b26\u4e32\u8fdb\u884c\u8f6c\u4e49\uff0c\u4f46\u5f80\u5f80\u5e76\u4e0d\u9700\u8981\u8f6c\u4e49\uff0c\u770b\u8d77\u6765\u4e0d\u6e05\u6670\u800c\u4e14\u5360\u7528\u5b58\u50a8\u7a7a\u95f4\u3002<\/p>\n<p>\u5bf9\u4e8e\u5982\u4e0b\u6570\u7ec4 <code>$a<\/code>\uff0c\u73b0\u6709\u4e24\u79cd\u529e\u6cd5\u89e3\u51b3\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-php\">$a = array(\n  &#039;http:\/\/www.appblog.cn&#039;,\n  &#039;http:\/\/www.baidu.com&#039;,\n  &#039;http:\/\/www.qq.com&#039;,\n  &#039;http:\/\/www.taobao.com&#039;\n);<\/code><\/pre>\n<h4>\u6b63\u5219\u66ff\u6362\uff1a<\/h4>\n<pre><code class=\"language-php\">$a = str_replace(&quot;\\\\\/&quot;, &quot;\/&quot;, json_encode($a));\nvar_dump($a);<\/code><\/pre>\n<h4>\u82e5 PHP\u7248\u672c\u662f 5.4 \u53ca\u4ee5\u4e0a\u7684\u8bdd\uff1a<\/h4>\n<pre><code class=\"language-php\">$a = json_encode($a, JSON_UNESCAPED_SLASHES);\nvar_dump($a);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0bPHP\u4f7f\u7528 json_encode \u5bf9\u6570\u7ec4\u8fdb\u884c json\u683c\u5f0f\u8f6c\u6362\u65f6\u4f1a\u81ea\u52a8\u5c06\u6570\u636e\u4e2d\u542b\u6709\u659c\u6760\u7684\u5b57\u7b26\u4e32\u8fdb\u884c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-php-basic"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}