{"id":879,"date":"2024-11-07T08:10:07","date_gmt":"2024-11-07T00:10:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/879\/"},"modified":"2024-11-07T08:10:07","modified_gmt":"2024-11-07T00:10:07","slug":"%e5%a6%82%e4%bd%95%e7%94%a8%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%8c%b9%e9%85%8d%e5%a4%9a%e4%b8%aa%e5%80%bc%e5%b9%b6%e4%be%9d%e6%ac%a1%e6%9b%bf%e6%8d%a2%e4%b8%ba%e4%b8%8d%e5%90%8c%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/879\/","title":{"rendered":"\u5982\u4f55\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u591a\u4e2a\u503c\u5e76\u4f9d\u6b21\u66ff\u6362\u4e3a\u4e0d\u540c\u503c\uff1f"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1026\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173034841953545.jpg\" width=\"720\" height=\"288\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173034841953545.jpg 720w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173034841953545-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/173034841953545-670x268.jpg 670w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" title=\"\u5982\u4f55\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u591a\u4e2a\u503c\u5e76\u4f9d\u6b21\u66ff\u6362\u4e3a\u4e0d\u540c\u503c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u591a\u4e2a\u503c\u5e76\u4f9d\u6b21\u66ff\u6362\u4e3a\u4e0d\u540c\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728\u6b63\u5219\u5339\u914d\u5230\u7684\u5185\u5bb9\u4e2d\u4f9d\u6b21\u66ff\u6362\u4e0d\u540c\u7684\u503c\uff1f<\/strong><\/p>\n<p>\u5728\u89e3\u51b3\u7f16\u7a0b\u95ee\u9898\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u5230\u7684\u591a\u4e2a\u503c\u9010\u4e00\u66ff\u6362\u4e3a\u4e0d\u540c\u7684\u65b0\u503c\u3002\u672c\u6587\u65e8\u5728\u4e3a\u60a8\u63d0\u4f9b\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0\uff1a<\/strong><\/p>\n<p>\u60a8\u5e0c\u671b\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u591a\u4e2a\u5b50\u5b57\u7b26\u4e32\uff0c\u5e76\u5206\u522b\u7528\u6765\u81ea\u53e6\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7684\u503c\u66ff\u6362\u5b83\u4eec\u3002\u4f8b\u5982\uff0c\u60a8\u8981\u5c06\u5339\u914d\u5230\u7684\u6240\u6709 &#8220;<strong><em>img<\/em><\/strong>&#8221; \u66ff\u6362\u4e3a\u53e6\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7684\u503c\uff0c\u5176\u4e2d $re_img \u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u867d\u7136\u63d0\u4f9b\u7684\u7b54\u6848\u6ca1\u6709\u76f4\u63a5\u89e3\u51b3\u4f7f\u7528 $re_img \u6570\u7ec4\u66ff\u6362\u5339\u914d\u5230\u7684\u503c\u7684\u95ee\u9898\uff0c\u4f46\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7c7b\u4f3c\u7684\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\u4f7f\u7528 preg_replace \u51fd\u6570\u5c06\u6240\u6709\u5339\u914d\u5230\u7684 &#8220;<strong><em>img<\/em><\/strong>&#8221; \u66ff\u6362\u4e3a\u4e00\u4e2a\u4e34\u65f6\u503c\uff0c\u4f8b\u5982 &#8220;placeholder&#8221;\u3002<\/li>\n<li>\u4f7f\u7528\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\uff0c\u4f8b\u5982 strpos \u6216\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u627e\u5230 &#8220;placeholder&#8221; \u5728\u66ff\u6362\u540e\u5b57\u7b26\u4e32\u4e2d\u7684\u4f4d\u7f6e\u3002<\/li>\n<li>\u5c06 $re_img \u6570\u7ec4\u7684\u503c\u63d2\u5165\u5230\u627e\u5230\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>$result1 = \"\u8fd9\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u591a\u4e2a ***img***\";\n$re_img = array(array(\"image1.jpg\", \"image2.jpg\", \"image3.jpg\"));\n\n\/\/ \u5c06\u6240\u6709 ***img*** \u66ff\u6362\u4e3a PLACEHOLDER\n$temp_str = preg_replace('\/***img***\/', 'PLACEHOLDER', $result1);\n\n\/\/ \u627e\u5230 PLACEHOLDER \u5728 temp_str \u4e2d\u7684\u4f4d\u7f6e\n$positions = array();\nwhile (($pos = strpos($temp_str, 'PLACEHOLDER')) !== false) {\n    $positions[] = $pos;\n}\n\n\/\/ \u7528 re_img \u4e2d\u7684\u503c\u66ff\u6362 PLACEHOLDER\nforeach ($positions as $key =&gt; $pos) {\n    $temp_str = substr_replace($temp_str, $re_img[0][$key], $pos, strlen('PLACEHOLDER'));\n}\n\necho $temp_str;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<p>&#8220;\u8fd9\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u591a\u4e2a image1.jpg&#8221;<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u591a\u4e2a\u503c\u5e76\u4f9d\u6b21\u66ff\u6362\u4e3a\u4e0d\u540c\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728\u6b63\u5219\u5339\u914d\u5230\u7684\u5185\u5bb9\u4e2d\u4f9d\u6b21\u66ff\u6362\u4e0d\u540c\u7684\u503c\uff1f \u5728\u89e3\u51b3\u7f16\u7a0b\u95ee\u9898\u65f6\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u5230\u7684\u591a\u4e2a\u503c\u9010\u4e00\u66ff\u6362\u4e3a\u4e0d\u540c\u7684\u65b0\u503c\u3002\u672c\u6587\u65e8\u5728\u4e3a\u60a8\u63d0\u4f9b\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002 \u95ee\u9898\u63cf\u8ff0\uff1a \u60a8\u5e0c\u671b\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u5230\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7684\u591a\u4e2a\u5b50\u5b57\u7b26\u4e32\uff0c\u5e76\u5206\u522b\u7528\u6765\u81ea\u53e6\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7684\u503c\u66ff\u6362\u5b83\u4eec\u3002\u4f8b\u5982\uff0c\u60a8\u8981\u5c06\u5339\u914d\u5230\u7684\u6240\u6709 &#8220;img&#8221; \u66ff\u6362\u4e3a\u53e6\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7684\u503c\uff0c\u5176\u4e2d $re_img \u662f\u4e00\u4e2a\u4e8c\u7ef4\u6570\u7ec4\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u867d\u7136\u63d0\u4f9b\u7684\u7b54\u6848\u6ca1\u6709\u76f4\u63a5\u89e3\u51b3\u4f7f\u7528 $re_img \u6570\u7ec4\u66ff\u6362\u5339\u914d\u5230\u7684\u503c\u7684\u95ee\u9898\uff0c\u4f46\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7c7b\u4f3c\u7684\u65b9\u6cd5\uff1a \u4f7f\u7528 preg_replace \u51fd\u6570\u5c06\u6240\u6709\u5339\u914d\u5230\u7684 &#8220;img&#8221; \u66ff\u6362\u4e3a\u4e00\u4e2a\u4e34\u65f6\u503c\uff0c\u4f8b\u5982 &#8220;placeholder&#8221;\u3002 \u4f7f\u7528\u5b57\u7b26\u4e32\u64cd\u4f5c\u51fd\u6570\uff0c\u4f8b\u5982 strpos \u6216\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u627e\u5230 &#8220;placeholder&#8221; \u5728\u66ff\u6362\u540e\u5b57\u7b26\u4e32\u4e2d\u7684\u4f4d\u7f6e\u3002 \u5c06 $re_img \u6570\u7ec4\u7684\u503c\u63d2\u5165\u5230\u627e\u5230\u7684\u4f4d\u7f6e\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a $result1 = &#8220;\u8fd9\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u591a\u4e2a ***img***&#8221;; $re_img = array(array(&#8220;image1.jpg&#8221;, &#8220;image2.jpg&#8221;, &#8220;image3.jpg&#8221;)); \/\/ \u5c06\u6240\u6709 ***img*** \u66ff\u6362\u4e3a PLACEHOLDER $temp_str = preg_replace(&#8216;\/***img***\/&#8217;, &#8216;PLACEHOLDER&#8217;, $result1); \/\/ \u627e\u5230 PLACEHOLDER \u5728 temp_str \u4e2d\u7684\u4f4d\u7f6e $positions = array(); [&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-879","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/879","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=879"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/879\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}