{"id":48593,"date":"2024-12-02T09:03:25","date_gmt":"2024-12-02T01:03:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48593\/"},"modified":"2024-12-02T09:03:25","modified_gmt":"2024-12-02T01:03:25","slug":"php-%e4%b8%ad-preg_replace-%e5%87%bd%e6%95%b0%e4%b8%ba%e4%bd%95%e6%97%a0%e6%b3%95%e5%8c%b9%e9%85%8d-t-%e5%92%8c-n%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48593\/","title":{"rendered":"PHP \u4e2d preg_replace \u51fd\u6570\u4e3a\u4f55\u65e0\u6cd5\u5339\u914d \\\\t \u548c \\\\n\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u4e2d preg_replace \u51fd\u6570\u4e3a\u4f55\u65e0\u6cd5\u5339\u914d \\\\t \u548c \\\\n\uff1f<\/h1>\n<p>\u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aPHP \u4e2d preg_replace \u51fd\u6570\u4e3a\u4f55\u65e0\u6cd5\u5339\u914d \\\\t \u548c \\\\n\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730108019671f5a73d76cb.jpg\" class=\"aligncenter\" title=\"PHP \u4e2d preg_replace \u51fd\u6570\u4e3a\u4f55\u65e0\u6cd5\u5339\u914d \\\\t \u548c \\\\n\uff1f\u63d2\u56fe\" alt=\"PHP \u4e2d preg_replace \u51fd\u6570\u4e3a\u4f55\u65e0\u6cd5\u5339\u914d \\\\t \u548c \\\\n\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>preg_replace \u5339\u914d\u81ea\u8eab\u4e3a\u4f55\u65e0\u6548<\/strong><\/p>\n<p>\u5728 php \u4e2d\uff0cpreg_replace \u51fd\u6570\u7528\u4e8e\u7528\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u66ff\u6362\u5339\u914d\u7684\u6a21\u5f0f\u3002\u7136\u800c\uff0c\u4f7f\u7528 t \u548c n \u66ff\u6362\u81ea\u8eab\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u610f\u60f3\u4e0d\u5230\u7684\u7ed3\u679c\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u4e3a\u4ec0\u4e48\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7528 t \u548c n \u5339\u914d\u81ea\u8eab\u4e0d\u8d77\u4f5c\u7528\uff1f<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u5f53\u5b57\u7b26\u4e32\u53d8\u91cf\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\u65f6\uff0c\u91cc\u9762\u7684\u8f6c\u4e49\u5e8f\u5217\u4e0d\u4f1a\u88ab\u89e3\u6790\u3002\u56e0\u6b64\uff0c\u5373\u4f7f\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u6307\u5b9a\u4e86 t \u548c n\uff0c\u4f46\u5b9e\u9645\u4e0a\u5b83\u4eec\u53ea\u662f\u6587\u672c\u4e2d\u7684\u5b57\u7b26\uff0c\u800c\u4e0d\u662f\u4e0d\u53ef\u89c1\u7684\u5236\u8868\u7b26\u6216\u6362\u884c\u7b26\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u8981\u6b63\u786e\u5339\u914d t \u548c n\uff0c\u9700\u8981\u5728\u5b57\u7b26\u4e32\u53d8\u91cf\u4e2d\u4f7f\u7528\u53cc\u5f15\u53f7\uff0c\u4ee5\u4fbf\u89e3\u6790\u8f6c\u4e49\u5e8f\u5217\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>$str = \"\u6211\u662f\\n\u4e00\u4e2a\u5b57\u7b26\u4e32\";\n$pattern = \"\/\\n\/\";\n$replacement = \"\";\n$result = preg_replace($pattern, $replacement, $str);\n\/\/ \u8f93\u51fa: \"\u6211\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\"<\/pre>\n<p><strong>\u7ed3\u8bba\uff1a<\/strong><\/p>\n<p>\u5728 php \u4e2d\u5339\u914d\u81ea\u8eab\u65f6\uff0c\u8bf7\u786e\u4fdd\u4f7f\u7528\u53cc\u5f15\u53f7\u62ec\u8d77\u5b57\u7b26\u4e32\u53d8\u91cf\uff0c\u4ee5\u5141\u8bb8\u8f6c\u4e49\u5e8f\u5217\u89e3\u6790\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u4e2d preg_replace \u51fd\u6570\u4e3a\u4f55\u65e0\u6cd5\u5339\u914d \\\\t \u548c \\\\n\uff1f \u4eb2\u7231\u7684\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5982\u679c\u4f60\u70b9\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8bf4\u660e\u4f60\u5bf9\u300aPHP \u4e2d preg_replace \u51fd\u6570\u4e3a\u4f55\u65e0\u6cd5\u5339\u914d \\\\t \u548c \\\\n\uff1f\u300b\u5f88\u611f\u5174\u8da3\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u8be6\u7ec6\u89e3\u6790\u4e00\u4e0b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u6240\u6709\u8ba4\u771f\u8bfb\u5b8c\u7684\u7ae5\u978b\u4eec\uff0c\u90fd\u6709\u5b9e\u8d28\u6027\u7684\u63d0\u9ad8\u3002 preg_replace \u5339\u914d\u81ea\u8eab\u4e3a\u4f55\u65e0\u6548 \u5728 php \u4e2d\uff0cpreg_replace \u51fd\u6570\u7528\u4e8e\u7528\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u66ff\u6362\u5339\u914d\u7684\u6a21\u5f0f\u3002\u7136\u800c\uff0c\u4f7f\u7528 t \u548c n \u66ff\u6362\u81ea\u8eab\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u610f\u60f3\u4e0d\u5230\u7684\u7ed3\u679c\u3002 \u95ee\u9898\uff1a \u4e3a\u4ec0\u4e48\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7528 t \u548c n \u5339\u914d\u81ea\u8eab\u4e0d\u8d77\u4f5c\u7528\uff1f \u539f\u56e0\uff1a \u5f53\u5b57\u7b26\u4e32\u53d8\u91cf\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\u65f6\uff0c\u91cc\u9762\u7684\u8f6c\u4e49\u5e8f\u5217\u4e0d\u4f1a\u88ab\u89e3\u6790\u3002\u56e0\u6b64\uff0c\u5373\u4f7f\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u6307\u5b9a\u4e86 t \u548c n\uff0c\u4f46\u5b9e\u9645\u4e0a\u5b83\u4eec\u53ea\u662f\u6587\u672c\u4e2d\u7684\u5b57\u7b26\uff0c\u800c\u4e0d\u662f\u4e0d\u53ef\u89c1\u7684\u5236\u8868\u7b26\u6216\u6362\u884c\u7b26\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u8981\u6b63\u786e\u5339\u914d t \u548c n\uff0c\u9700\u8981\u5728\u5b57\u7b26\u4e32\u53d8\u91cf\u4e2d\u4f7f\u7528\u53cc\u5f15\u53f7\uff0c\u4ee5\u4fbf\u89e3\u6790\u8f6c\u4e49\u5e8f\u5217\u3002\u4f8b\u5982\uff1a $str = &#8220;\u6211\u662f\\n\u4e00\u4e2a\u5b57\u7b26\u4e32&#8221;; $pattern = &#8220;\/\\n\/&#8221;; $replacement = &#8220;&#8221;; $result = preg_replace($pattern, $replacement, $str); \/\/ [&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-48593","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48593","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=48593"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48593\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}