{"id":48752,"date":"2024-12-02T09:08:43","date_gmt":"2024-12-02T01:08:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48752\/"},"modified":"2024-12-02T09:08:43","modified_gmt":"2024-12-02T01:08:43","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88%e5%9c%a8-php-%e4%b8%ad%e4%bd%bf%e7%94%a8-preg_replace-%e6%9b%bf%e6%8d%a2-n-%e5%92%8c-t-%e6%97%b6%ef%bc%8c%e5%8c%b9%e9%85%8d%e5%92%8c%e6%9b%bf%e6%8d%a2%e6%97%a0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48752\/","title":{"rendered":"\u4e3a\u4ec0\u4e48\u5728 PHP \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 \\\\n \u548c \\\\t \u65f6\uff0c\u5339\u914d\u548c\u66ff\u6362\u65e0\u6548\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4e3a\u4ec0\u4e48\u5728 PHP \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 \\\\n \u548c \\\\t \u65f6\uff0c\u5339\u914d\u548c\u66ff\u6362\u65e0\u6548\uff1f<\/h1>\n<p><span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898<span style=\"color: #222222;, sans-serif;background-color: #FFFFFF\">\u662f<\/span><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u4e3a\u4ec0\u4e48\u5728 PHP \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 \\\\n \u548c \\\\t \u65f6\uff0c\u5339\u914d\u548c\u66ff\u6362\u65e0\u6548\uff1f\u300b<\/span>\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241031\/17303328356722c8a35df08.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48\u5728 PHP \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 \\\\n \u548c \\\\t \u65f6\uff0c\u5339\u914d\u548c\u66ff\u6362\u65e0\u6548\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48\u5728 PHP \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 \\\\n \u548c \\\\t \u65f6\uff0c\u5339\u914d\u548c\u66ff\u6362\u65e0\u6548\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>preg_replace \u4e2d t \u548c n \u5339\u914d\u81ea\u8eab\u65e0\u6548\u7684\u539f\u56e0<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5728 php \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 n \u548c t \u65f6\uff0c\u5c3d\u7ba1\u5df2\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u8f6c\u4e49\u4e3a t \u548c n\uff0c\u4f46\u5339\u914d\u548c\u66ff\u6362\u4ecd\u65e0\u6548\u3002<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<p>\u5982\u679c\u5b57\u7b26\u4e32\u53d8\u91cf\u662f\u7528\u5355\u5f15\u53f7 (&#8216;) \u5305\u88f9\u7684\uff0c\u800c\u4e0d\u662f\u53cc\u5f15\u53f7 (&#8220;)\uff0c\u5219\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u8f6c\u4e49\u5b57\u7b26\u4e0d\u4f1a\u88ab\u89e3\u6790\u3002\u56e0\u6b64\uff0cn \u548c t \u5c06\u88ab\u89c6\u4e3a\u5b9e\u9645\u5b57\u7b26\uff0c\u800c\u4e0d\u662f\u4e0d\u53ef\u89c1\u5b57\u7b26\uff08\u6362\u884c\u7b26\u6216\u5236\u8868\u7b26\uff09\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u8981\u6b63\u786e\u5339\u914d n \u548c t \u672c\u8eab\uff0c\u9700\u8981\u4f7f\u7528\u53cc\u5f15\u53f7 (&#8220;) \u5c06\u5b57\u7b26\u4e32\u53d8\u91cf\u62ec\u8d77\u6765\uff0c\u4ee5\u5141\u8bb8\u8f6c\u4e49\u5b57\u7b26\u88ab\u89e3\u6790\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>$string = \"this is a string with \\n and \\t\";\n\n\/\/ \u4e0d\u4f1a\u5339\u914d \\n \u548c \\t\n$result1 = preg_replace('\/\\n|\\t\/', '', $string);\n\n\/\/ \u6b63\u786e\u5339\u914d \\n \u548c \\t\n$result2 = preg_replace('\/\\\\\\\\n|\\\\\\\\t\/', '', $string);<\/pre>\n<p>\u5728\u7b2c\u4e8c\u4e2a\u793a\u4f8b\u4e2d\uff0c\u7531\u4e8e\u4f7f\u7528\u4e86\u53cc\u5f15\u53f7\uff0c\u6240\u4ee5\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684 n \u548c t \u53ef\u4ee5\u88ab\u89e3\u6790\u4e3a\u4e0d\u53ef\u89c1\u5b57\u7b26\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u4e3a\u4ec0\u4e48\u5728 PHP \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 \\\\n \u548c \\\\t \u65f6\uff0c\u5339\u914d\u548c\u66ff\u6362\u65e0\u6548\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4ec0\u4e48\u5728 PHP \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 \\\\n \u548c \\\\t \u65f6\uff0c\u5339\u914d\u548c\u66ff\u6362\u65e0\u6548\uff1f \u5404\u4f4d\u5c0f\u4f19\u4f34\u4eec\uff0c\u5927\u5bb6\u597d\u5440\uff01\u770b\u770b\u4eca\u5929\u6211\u53c8\u7ed9\u5404\u4f4d\u5e26\u6765\u4e86\u4ec0\u4e48\u6587\u7ae0\uff1f\u672c\u6587\u6807\u9898\u662f\u300a\u4e3a\u4ec0\u4e48\u5728 PHP \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 \\\\n \u548c \\\\t \u65f6\uff0c\u5339\u914d\u548c\u66ff\u6362\u65e0\u6548\uff1f\u300b\uff0c\u5f88\u660e\u663e\u662f\u5173\u4e8e\u6587\u7ae0\u7684\u6587\u7ae0\u54c8\u54c8\u54c8\uff0c\u5176\u4e2d\u5185\u5bb9\u4e3b\u8981\u4f1a\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u80fd\u5e2e\u5230\u4f60\uff0c\u89c9\u5f97\u5f88\u4e0d\u9519\u7684\u8bdd\uff0c\u6b22\u8fce\u5404\u4f4d\u591a\u591a\u70b9\u8bc4\u548c\u5206\u4eab\uff01 preg_replace \u4e2d t \u548c n \u5339\u914d\u81ea\u8eab\u65e0\u6548\u7684\u539f\u56e0 \u95ee\u9898\uff1a \u5728 php \u4e2d\u4f7f\u7528 preg_replace() \u66ff\u6362 n \u548c t \u65f6\uff0c\u5c3d\u7ba1\u5df2\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u8f6c\u4e49\u4e3a t \u548c n\uff0c\u4f46\u5339\u914d\u548c\u66ff\u6362\u4ecd\u65e0\u6548\u3002 \u539f\u56e0\uff1a \u5982\u679c\u5b57\u7b26\u4e32\u53d8\u91cf\u662f\u7528\u5355\u5f15\u53f7 (&#8216;) \u5305\u88f9\u7684\uff0c\u800c\u4e0d\u662f\u53cc\u5f15\u53f7 (&#8220;)\uff0c\u5219\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u8f6c\u4e49\u5b57\u7b26\u4e0d\u4f1a\u88ab\u89e3\u6790\u3002\u56e0\u6b64\uff0cn \u548c t \u5c06\u88ab\u89c6\u4e3a\u5b9e\u9645\u5b57\u7b26\uff0c\u800c\u4e0d\u662f\u4e0d\u53ef\u89c1\u5b57\u7b26\uff08\u6362\u884c\u7b26\u6216\u5236\u8868\u7b26\uff09\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u8981\u6b63\u786e\u5339\u914d n \u548c t \u672c\u8eab\uff0c\u9700\u8981\u4f7f\u7528\u53cc\u5f15\u53f7 (&#8220;) \u5c06\u5b57\u7b26\u4e32\u53d8\u91cf\u62ec\u8d77\u6765\uff0c\u4ee5\u5141\u8bb8\u8f6c\u4e49\u5b57\u7b26\u88ab\u89e3\u6790\u3002\u4f8b\u5982\uff1a $string = [&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-48752","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48752","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=48752"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48752\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48752"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}