{"id":47892,"date":"2024-12-02T16:52:26","date_gmt":"2024-12-02T08:52:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47892\/"},"modified":"2024-12-02T16:52:26","modified_gmt":"2024-12-02T08:52:26","slug":"php%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%a6%82%e4%bd%95%e5%a4%84%e7%90%86%e8%be%b9%e7%95%8c%e5%8c%b9%e9%85%8d%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47892\/","title":{"rendered":"php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u5904\u7406\u8fb9\u754c\u5339\u914d\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u5904\u7406\u8fb9\u754c\u5339\u914d\uff1f<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aphp\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u5904\u7406\u8fb9\u754c\u5339\u914d\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p>PHP\u6b63\u5219\u8868\u8fbe\u5f0fBoundary Matchers\u53ef\u5339\u914d\u884c\u9996\u5b57\u7b26\uff08^\uff09\u3001\u884c\u5c3e\u5b57\u7b26\uff08$\uff09\u3001\u5355\u8bcd\u8fb9\u754c\uff08\\b\uff09\u3002\u4f7f\u7528^\u53ef\u5339\u914d\u4ee5\u7279\u5b9a\u5355\u8bcd\u5f00\u5934\u7684\u884c\uff08\u4f8b\u5982\uff0cpreg_match(&#8220;\/^This\/&#8221;, $str)\uff09\uff0c\u4f7f\u7528$\u53ef\u5339\u914d\u4ee5\u7279\u5b9a\u5355\u8bcd\u7ed3\u5c3e\u7684\u884c\uff08\u4f8b\u5982\uff0cpreg_match(&#8220;\/text\\.$\/&#8221;, $str)\uff09\uff0c\u4f7f\u7528\\b\u53ef\u5339\u914d\u5355\u8bcd\u8fb9\u754c\u5185\u7684\u7279\u5b9a\u5355\u8bcd\uff08\u4f8b\u5982\uff0cpreg_match(&#8220;\/\\bsample\\b\/&#8221;, $str)\uff09\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729941627671cd07b6ddff.jpg\" class=\"aligncenter\" title=\"php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u5904\u7406\u8fb9\u754c\u5339\u914d\uff1f\u63d2\u56fe\" alt=\"php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u5904\u7406\u8fb9\u754c\u5339\u914d\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u6b63\u5219\u8868\u8fbe\u5f0f Boundary Matchers \u7684\u4f7f\u7528<\/strong><\/p>\n<p>\u8fb9\u754c\u5339\u914d\u5668\u662f\u4e00\u79cd\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\uff0c\u5b83\u5141\u8bb8\u4f60\u5339\u914d\u884c\u9996\u6216\u884c\u5c3e\u7684\u7279\u5b9a\u5b57\u7b26\u6216\u5b50\u4e32\u3002\u8fd9\u4e9b\u8fb9\u754c\u5339\u914d\u5668\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>^<\/code>\uff1a\u5339\u914d\u884c\u9996<\/li>\n<li><code>$<\/code>\uff1a\u5339\u914d\u884c\u5c3e<\/li>\n<li><code>\\b<\/code>\uff1a\u5339\u914d\u5355\u8bcd\u8fb9\u754c\uff08\u5373\u5355\u8bcd\u9996\u6216\u5355\u8bcd\u5c3e\uff09<\/li>\n<\/ul>\n<p><strong>\u5b9e\u9645\u6848\u4f8b\uff1a<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u5982\u4e0b\uff1a<\/p>\n<pre>$str = \"This is a sample text.\";<\/pre>\n<p><strong>\u5339\u914d\u884c\u9996\u7684\u7279\u5b9a\u5355\u8bcd<\/strong><\/p>\n<p>\u4f7f\u7528 <code>^<\/code> \u5339\u914d\u5668\u53ef\u4ee5\u5339\u914d\u4ee5 &#8220;This&#8221; \u5f00\u5934\u7684\u884c\uff1a<\/p>\n<pre>preg_match(\"\/^This\/\", $str);<\/pre>\n<p><strong>\u5339\u914d\u884c\u5c3e\u7684\u7279\u5b9a\u5355\u8bcd<\/strong><\/p>\n<p>\u4f7f\u7528 <code>$<\/code> \u5339\u914d\u5668\u53ef\u4ee5\u5339\u914d\u4ee5 &#8220;text.&#8221; \u7ed3\u5c3e\u7684\u884c\uff1a<\/p>\n<pre>preg_match(\"\/text\\.$\/\", $str);<\/pre>\n<p><strong>\u5339\u914d\u5355\u8bcd\u8fb9\u754c\u5185\u7684\u7279\u5b9a\u5355\u8bcd<\/strong><\/p>\n<p>\u4f7f\u7528 <code>\\b<\/code> \u5339\u914d\u5668\u53ef\u4ee5\u5339\u914d &#8220;sample&#8221; \u8fd9\u4e2a\u5355\u8bcd\uff1a<\/p>\n<pre>preg_match(\"\/\\bsample\\b\/\", $str);<\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u5982\u679c\u4f60\u540c\u65f6\u4f7f\u7528 <code>^<\/code> \u548c <code>$<\/code> \u5339\u914d\u5668\uff0c\u5219\u5b83\u5c06\u5339\u914d\u6574\u4e2a\u5b57\u7b26\u4e32\u3002<\/li>\n<li><code>\\b<\/code> \u5339\u914d\u5668\u8fd8\u53ef\u4ee5\u5728\u5355\u8bcd\u8fb9\u754c\u4e4b\u5916\u5339\u914d Unicode \u5b57\u7b26\u7c7b\u522b\uff0c\u5982\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u3002<\/li>\n<li>Boundary matchers \u53ef\u4ee5\u4e0e\u5176\u4ed6\u6b63\u5219\u8868\u8fbe\u5f0f\u56fe\u6848\u7ed3\u5408\u4f7f\u7528\u4ee5\u521b\u5efa\u66f4\u5f3a\u5927\u7684\u5339\u914d\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aphp\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u5904\u7406\u8fb9\u754c\u5339\u914d\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u5904\u7406\u8fb9\u754c\u5339\u914d\uff1f \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aphp\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u5904\u7406\u8fb9\u754c\u5339\u914d\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 PHP\u6b63\u5219\u8868\u8fbe\u5f0fBoundary Matchers\u53ef\u5339\u914d\u884c\u9996\u5b57\u7b26\uff08^\uff09\u3001\u884c\u5c3e\u5b57\u7b26\uff08$\uff09\u3001\u5355\u8bcd\u8fb9\u754c\uff08\\b\uff09\u3002\u4f7f\u7528^\u53ef\u5339\u914d\u4ee5\u7279\u5b9a\u5355\u8bcd\u5f00\u5934\u7684\u884c\uff08\u4f8b\u5982\uff0cpreg_match(&#8220;\/^This\/&#8221;, $str)\uff09\uff0c\u4f7f\u7528$\u53ef\u5339\u914d\u4ee5\u7279\u5b9a\u5355\u8bcd\u7ed3\u5c3e\u7684\u884c\uff08\u4f8b\u5982\uff0cpreg_match(&#8220;\/text\\.$\/&#8221;, $str)\uff09\uff0c\u4f7f\u7528\\b\u53ef\u5339\u914d\u5355\u8bcd\u8fb9\u754c\u5185\u7684\u7279\u5b9a\u5355\u8bcd\uff08\u4f8b\u5982\uff0cpreg_match(&#8220;\/\\bsample\\b\/&#8221;, $str)\uff09\u3002 PHP \u6b63\u5219\u8868\u8fbe\u5f0f Boundary Matchers \u7684\u4f7f\u7528 \u8fb9\u754c\u5339\u914d\u5668\u662f\u4e00\u79cd\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\uff0c\u5b83\u5141\u8bb8\u4f60\u5339\u914d\u884c\u9996\u6216\u884c\u5c3e\u7684\u7279\u5b9a\u5b57\u7b26\u6216\u5b50\u4e32\u3002\u8fd9\u4e9b\u8fb9\u754c\u5339\u914d\u5668\u5305\u62ec\uff1a ^\uff1a\u5339\u914d\u884c\u9996 $\uff1a\u5339\u914d\u884c\u5c3e \\b\uff1a\u5339\u914d\u5355\u8bcd\u8fb9\u754c\uff08\u5373\u5355\u8bcd\u9996\u6216\u5355\u8bcd\u5c3e\uff09 \u5b9e\u9645\u6848\u4f8b\uff1a \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\u5982\u4e0b\uff1a $str = &#8220;This is a sample text.&#8221;; \u5339\u914d\u884c\u9996\u7684\u7279\u5b9a\u5355\u8bcd \u4f7f\u7528 ^ \u5339\u914d\u5668\u53ef\u4ee5\u5339\u914d\u4ee5 &#8220;This&#8221; \u5f00\u5934\u7684\u884c\uff1a preg_match(&#8220;\/^This\/&#8221;, $str); \u5339\u914d\u884c\u5c3e\u7684\u7279\u5b9a\u5355\u8bcd \u4f7f\u7528 $ \u5339\u914d\u5668\u53ef\u4ee5\u5339\u914d\u4ee5 &#8220;text.&#8221; \u7ed3\u5c3e\u7684\u884c\uff1a preg_match(&#8220;\/text\\.$\/&#8221;, $str); \u5339\u914d\u5355\u8bcd\u8fb9\u754c\u5185\u7684\u7279\u5b9a\u5355\u8bcd \u4f7f\u7528 \\b \u5339\u914d\u5668\u53ef\u4ee5\u5339\u914d &#8220;sample&#8221; \u8fd9\u4e2a\u5355\u8bcd\uff1a preg_match(&#8220;\/\\bsample\\b\/&#8221;, $str); \u6ce8\u610f\uff1a \u5982\u679c\u4f60\u540c\u65f6\u4f7f\u7528 ^ \u548c $ \u5339\u914d\u5668\uff0c\u5219\u5b83\u5c06\u5339\u914d\u6574\u4e2a\u5b57\u7b26\u4e32\u3002 [&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-47892","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47892","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=47892"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47892\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}