{"id":48599,"date":"2024-12-02T17:28:42","date_gmt":"2024-12-02T09:28:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48599\/"},"modified":"2024-12-02T17:28:42","modified_gmt":"2024-12-02T09:28:42","slug":"php-%e4%b8%ad-preg_replace-%e5%8c%b9%e9%85%8d%e8%bd%ac%e4%b9%89%e6%8d%a2%e8%a1%8c%e7%ac%a6%e5%92%8c%e5%88%b6%e8%a1%a8%e7%ac%a6%e4%b8%8d%e7%94%9f%e6%95%88%e7%9a%84%e5%8e%9f%e5%9b%a0%e6%98%af%e4%bb%80","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48599\/","title":{"rendered":"PHP \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\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\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730111799671f69374bb7a.jpg\" class=\"aligncenter\" title=\"PHP \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"PHP \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0<\/strong><\/p>\n<p>\u6211\u4eec\u5728\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u6362\u884c\u7b26\uff08n\uff09\u548c\u5236\u8868\u7b26\uff08t\uff09\u7b49\u4e0d\u53ef\u89c1\u5b57\u7b26\u65f6\uff0c\u9700\u8981\u5bf9\u5b83\u4eec\u8fdb\u884c\u8f6c\u4e49\u4ee5\u907f\u514d\u7279\u6b8a\u542b\u4e49\u3002\u7136\u800c\uff0c\u5728 preg_replace \u4e2d\uff0c\u4f7f\u7528\u539f\u59cb\u5b57\u7b26\u4e32\uff08\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u4e32\uff09\u4f1a\u5bfc\u81f4\u8f6c\u4e49\u5b57\u7b26\u4e0d\u4f1a\u88ab\u89e3\u91ca\uff0c\u4ece\u800c\u5bfc\u81f4\u5339\u914d\u5931\u8d25\u3002<\/p>\n<p><strong>\u6848\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u539f\u59cb\u5b57\u7b26\u4e32\uff0c\u8f6c\u4e49\u5b57\u7b26\u4e0d\u4f1a\u88ab\u89e3\u91ca\n$input = '\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709\\n\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32';\n$output = preg_replace(\"\/\\n\/\", 'newline', $input);\necho $output; \/\/ \u8f93\u51fa\uff1a\"\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709\\n\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32\"<\/pre>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u5982\u4e0a\u4f8b\u6240\u793a\uff0c\u5c3d\u7ba1\u6b63\u5219\u8868\u8fbe\u5f0f\u5df2\u6b63\u786e\u8f6c\u4e49\u6362\u884c\u7b26\uff0c\u4f46\u7531\u4e8e\u5b57\u7b26\u4e32\u662f\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\u7684\uff0c\u5bfc\u81f4\u8f6c\u4e49\u5b57\u7b26\u4e0d\u4f1a\u88ab\u89e3\u91ca\u3002\u5b9e\u9645\u4e0a\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684 &#8220;n&#8221; \u88ab\u89c6\u4e3a\u4e24\u4e2a\u5355\u72ec\u7684\u5b57\u7b26\uff1a\u4e00\u4e2a\u53cd\u659c\u6760\u548c\u4e00\u4e2a\u5b57\u6bcd &#8220;n&#8221;\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u7684\u5b57\u7b26\u4e32\uff0c\u5728\u53cc\u5f15\u53f7\u5b57\u7b26\u4e32\u4e2d\u8f6c\u4e49\u5b57\u7b26\u5c06\u88ab\u89e3\u91ca\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>\/\/ \u53cc\u5f15\u53f7\u5b57\u7b26\u4e32\uff0c\u8f6c\u4e49\u5b57\u7b26\u4f1a\u88ab\u89e3\u91ca\n$input = \"\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709\\n\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32\";\n$output = preg_replace(\"\/\\n\/\", 'NEWLINE', $input);\necho $output; \/\/ \u8f93\u51fa\uff1a\"\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709NEWLINE\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32\"<\/pre>\n<p>\u603b\u4e4b\uff0c\u5728 php \u4e2d\u4f7f\u7528 preg_replace \u5339\u914d\u4e0d\u53ef\u89c1\u5b57\u7b26\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u7684\u5b57\u7b26\u4e32\u4ee5\u786e\u4fdd\u8f6c\u4e49\u5b57\u7b26\u88ab\u6b63\u786e\u89e3\u91ca\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPHP \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f \u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u300aPHP \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01 php \u4e2d preg_replace \u5339\u914d\u8f6c\u4e49\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u4e0d\u751f\u6548\u7684\u539f\u56e0 \u6211\u4eec\u5728\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u6362\u884c\u7b26\uff08n\uff09\u548c\u5236\u8868\u7b26\uff08t\uff09\u7b49\u4e0d\u53ef\u89c1\u5b57\u7b26\u65f6\uff0c\u9700\u8981\u5bf9\u5b83\u4eec\u8fdb\u884c\u8f6c\u4e49\u4ee5\u907f\u514d\u7279\u6b8a\u542b\u4e49\u3002\u7136\u800c\uff0c\u5728 preg_replace \u4e2d\uff0c\u4f7f\u7528\u539f\u59cb\u5b57\u7b26\u4e32\uff08\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u4e32\uff09\u4f1a\u5bfc\u81f4\u8f6c\u4e49\u5b57\u7b26\u4e0d\u4f1a\u88ab\u89e3\u91ca\uff0c\u4ece\u800c\u5bfc\u81f4\u5339\u914d\u5931\u8d25\u3002 \u6848\u4f8b\uff1a \/\/ \u539f\u59cb\u5b57\u7b26\u4e32\uff0c\u8f6c\u4e49\u5b57\u7b26\u4e0d\u4f1a\u88ab\u89e3\u91ca $input = &#8216;\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709\\n\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32&#8217;; $output = preg_replace(&#8220;\/\\n\/&#8221;, &#8216;newline&#8217;, $input); echo $output; \/\/ \u8f93\u51fa\uff1a&#8221;\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709\\n\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32&#8221; \u539f\u56e0\uff1a \u5982\u4e0a\u4f8b\u6240\u793a\uff0c\u5c3d\u7ba1\u6b63\u5219\u8868\u8fbe\u5f0f\u5df2\u6b63\u786e\u8f6c\u4e49\u6362\u884c\u7b26\uff0c\u4f46\u7531\u4e8e\u5b57\u7b26\u4e32\u662f\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\u7684\uff0c\u5bfc\u81f4\u8f6c\u4e49\u5b57\u7b26\u4e0d\u4f1a\u88ab\u89e3\u91ca\u3002\u5b9e\u9645\u4e0a\uff0c\u5b57\u7b26\u4e32\u4e2d\u7684 &#8220;n&#8221; \u88ab\u89c6\u4e3a\u4e24\u4e2a\u5355\u72ec\u7684\u5b57\u7b26\uff1a\u4e00\u4e2a\u53cd\u659c\u6760\u548c\u4e00\u4e2a\u5b57\u6bcd &#8220;n&#8221;\u3002 \u89e3\u51b3\u65b9\u6cd5\uff1a \u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u7684\u5b57\u7b26\u4e32\uff0c\u5728\u53cc\u5f15\u53f7\u5b57\u7b26\u4e32\u4e2d\u8f6c\u4e49\u5b57\u7b26\u5c06\u88ab\u89e3\u91ca\u3002\u4f8b\u5982\uff1a \/\/ \u53cc\u5f15\u53f7\u5b57\u7b26\u4e32\uff0c\u8f6c\u4e49\u5b57\u7b26\u4f1a\u88ab\u89e3\u91ca $input = &#8220;\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709\\n\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32&#8221;; $output = preg_replace(&#8220;\/\\n\/&#8221;, &#8216;NEWLINE&#8217;, $input); echo $output; \/\/ \u8f93\u51fa\uff1a&#8221;\u8fd9\u662f\u4e00\u4e2a\u5e26\u6709NEWLINE\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32&#8221; \u603b\u4e4b\uff0c\u5728 php \u4e2d\u4f7f\u7528 preg_replace [&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-48599","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48599","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=48599"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48599\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}