{"id":49212,"date":"2024-12-02T09:44:24","date_gmt":"2024-12-02T01:44:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/49212\/"},"modified":"2024-12-02T09:44:24","modified_gmt":"2024-12-02T01:44:24","slug":"php-%e8%af%bb%e5%8f%96-mysql-%e6%95%b0%e6%8d%ae%e8%bd%ac-json-%e5%90%8e%ef%bc%8curl-%e4%b8%ad%e7%9a%84%e6%96%9c%e6%9d%a0%e5%8f%98%e4%b8%ba%e5%8f%8d%e6%96%9c%e6%9d%a0%ef%bc%8c%e5%a6%82%e4%bd%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/49212\/","title":{"rendered":"PHP \u8bfb\u53d6 MySQL \u6570\u636e\u8f6c JSON \u540e\uff0cURL \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u8bfb\u53d6 MySQL \u6570\u636e\u8f6c JSON \u540e\uff0cURL \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760\uff0c\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7c73\u4e91\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u8bfb\u53d6 MySQL \u6570\u636e\u8f6c JSON \u540e\uff0cURL \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b<\/span>\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241117\/17318342266739b172c6b17.jpg\" class=\"aligncenter\" title=\"PHP \u8bfb\u53d6 MySQL \u6570\u636e\u8f6c JSON \u540e\uff0cURL \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"PHP \u8bfb\u53d6 MySQL \u6570\u636e\u8f6c JSON \u540e\uff0cURL \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php \u8bfb\u53d6 mysql \u6570\u636e\u540e\uff0cjson_encode \u4e2d\u7684 url \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760<\/strong><\/p>\n<p>\u5728\u8bfb\u53d6 mysql \u4e2d\u5305\u542b url \u7684\u6570\u636e\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a json \u65f6\uff0c\u6709\u65f6\u4f1a\u53d1\u73b0\u659c\u6760\uff08\/\uff09\u88ab\u66ff\u6362\u4e3a\u53cd\u659c\u6760\uff08\/\uff09\u3002\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u65b9\u6848\u5982\u4e0b\uff1a<\/p>\n<p>\u4ee3\u7801\u4e2d\u8bfb\u53d6\u56fe\u50cf\u5730\u5740\u540e\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u884c\uff1a<\/p>\n<pre>$array = str_replace(\"\\\/\", \"\/\", json_encode($arr));<\/pre>\n<p>\u4e0a\u9762\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u5c06 json \u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709 &#8220;\/&#8221; \u66ff\u6362\u4e3a &#8220;\/&#8221;, \u4ece\u800c\u8fd8\u539f\u539f\u59cb url\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b\uff1a<\/p>\n<pre>while ($row = mysql_fetch_array($result)) {\n    $image = iconv(\"GBk\", \"UTF-8\/\/IGNORE\", $row['image']);\n    $tmp = array(\n        'goodID' =&gt; $row['ID'],\n        'goodName' =&gt; $row['name'],\n        'goodPrice' =&gt; $row['price'],\n        'memo' =&gt; $row['memo'],\n        'image' =&gt; $image,\n        'companyID' =&gt; $row['companyID'],\n        'companyName' =&gt; $row['company'],\n        'companyAdd' =&gt; $row['address'],\n        'companyPhone' =&gt; $row['phone']\n    );\n    array_push($arr, $tmp);\n}\nmysql_close($con);\n\n\/\/ \u66ff\u6362\u53cd\u659c\u6760\n$array = str_replace(\"\\\\\/\", \"\/\", json_encode($arr));\n\nreturn $array;<\/pre>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPHP \u8bfb\u53d6 MySQL \u6570\u636e\u8f6c JSON \u540e\uff0cURL \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u8bfb\u53d6 MySQL \u6570\u636e\u8f6c JSON \u540e\uff0cURL \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760\uff0c\u5982\u4f55\u89e3\u51b3\uff1f \u54c8\u55bd\uff01\u5927\u5bb6\u597d\uff0c\u5f88\u9ad8\u5174\u53c8\u89c1\u9762\u4e86\uff0c\u6211\u662f\u7c73\u4e91\u7684\u4e00\u540d\u4f5c\u8005\uff0c\u4eca\u5929\u7531\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300aPHP \u8bfb\u53d6 MySQL \u6570\u636e\u8f6c JSON \u540e\uff0cURL \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u672c\u6587\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u5927\u5bb6\u4e00\u8d77\u5b66\u4e60\u8fdb\u6b65\uff0c\u4e5f\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u3001\u70b9\u8d5e\u3001\u6536\u85cf\u3001\u8f6c\u53d1! \u4e0b\u9762\u5c31\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 php \u8bfb\u53d6 mysql \u6570\u636e\u540e\uff0cjson_encode \u4e2d\u7684 url \u4e2d\u7684\u659c\u6760\u53d8\u4e3a\u53cd\u659c\u6760 \u5728\u8bfb\u53d6 mysql \u4e2d\u5305\u542b url \u7684\u6570\u636e\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a json \u65f6\uff0c\u6709\u65f6\u4f1a\u53d1\u73b0\u659c\u6760\uff08\/\uff09\u88ab\u66ff\u6362\u4e3a\u53cd\u659c\u6760\uff08\/\uff09\u3002\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u65b9\u6848\u5982\u4e0b\uff1a \u4ee3\u7801\u4e2d\u8bfb\u53d6\u56fe\u50cf\u5730\u5740\u540e\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u884c\uff1a $array = str_replace(&#8220;\\\/&#8221;, &#8220;\/&#8221;, json_encode($arr)); \u4e0a\u9762\u4ee3\u7801\u7684\u4f5c\u7528\u662f\u5c06 json \u5b57\u7b26\u4e32\u4e2d\u7684\u6240\u6709 &#8220;\/&#8221; \u66ff\u6362\u4e3a &#8220;\/&#8221;, \u4ece\u800c\u8fd8\u539f\u539f\u59cb url\u3002 \u4fee\u6539\u540e\u7684\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b\uff1a while ($row = mysql_fetch_array($result)) { $image = iconv(&#8220;GBk&#8221;, &#8220;UTF-8\/\/IGNORE&#8221;, $row[&#8216;image&#8217;]); $tmp [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-49212","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=49212"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/49212\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=49212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=49212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=49212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}