{"id":46917,"date":"2024-12-02T12:43:51","date_gmt":"2024-12-02T04:43:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46917\/"},"modified":"2024-12-02T12:43:51","modified_gmt":"2024-12-02T04:43:51","slug":"php%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e5%a6%82%e4%bd%95%e4%b8%8e%e6%95%b0%e6%8d%ae%e5%ba%93%e6%9f%a5%e8%af%a2%e9%85%8d%e5%90%88%e4%bd%bf%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46917\/","title":{"rendered":"php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u914d\u5408\u4f7f\u7528\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u914d\u5408\u4f7f\u7528\uff1f<\/h1>\n<p>\u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aphp\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u914d\u5408\u4f7f\u7528\uff1f\u300b<\/span>\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729854328671b7b78a7ea4.jpg\" class=\"aligncenter\" title=\"php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u914d\u5408\u4f7f\u7528\uff1f\u63d2\u56fe\" alt=\"php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u914d\u5408\u4f7f\u7528\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>PHP \u6b63\u5219\u8868\u8fbe\u5f0f\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u7684\u6574\u5408<\/h2>\n<p>PHP \u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u7684\u65b9\u6cd5\u6765\u5339\u914d\u5b57\u7b26\u4e32\u6a21\u5f0f\u3002\u5b83\u53ef\u4ee5\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u76f8\u7ed3\u5408\uff0c\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u641c\u7d22\u548c\u7b5b\u9009\u529f\u80fd\u3002<\/p>\n<h3>\u8bed\u6cd5<\/h3>\n<p>\u4f7f\u7528 PHP \u4e2d\u7684 <code>preg_match()<\/code> \u51fd\u6570\u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u76f8\u7ed3\u5408\uff1a<\/p>\n<pre>preg_match($regex, $data)<\/pre>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li><code>$regex<\/code> \u662f\u8981\u5339\u914d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f<\/li>\n<li><code>$data<\/code>\u662f\u8981\u67e5\u8be2\u7684\u6570\u636e\uff08\u4f8b\u5982\uff0c\u6570\u636e\u5e93\u884c\u7684\u5185\u5bb9\uff09<\/li>\n<\/ul>\n<p>\u5982\u679c\u6b63\u5219\u8868\u8fbe\u5f0f\u4e0e\u6570\u636e\u5339\u914d\uff0c<code>preg_match()<\/code> \u5c06\u8fd4\u56de 1\u3002\u5426\u5219\uff0c\u5b83\u5c06\u8fd4\u56de 0\u3002<\/p>\n<h3>\u5b9e\u6218\u6848\u4f8b<\/h3>\n<p><strong>\u6848\u4f8b\uff1a\u67e5\u627e\u5305\u542b\u7279\u5b9a\u6570\u5b57\u7684\u884c<\/strong><\/p>\n<p><strong>\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>$query = \"SELECT * FROM table WHERE field REGEXP '[0-9]+'\";<\/pre>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<p>\u8be5\u67e5\u8be2\u5c06\u8fd4\u56de\u5305\u542b\u81f3\u5c11\u4e00\u4e2a\u6570\u5b57\u7684\u884c\u3002<\/p>\n<p><strong>\u6848\u4f8b\uff1a\u67e5\u627e\u4ee5\u7279\u5b9a\u524d\u7f00\u5f00\u5934\u7684\u884c<\/strong><\/p>\n<p><strong>\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>$query = \"SELECT * FROM table WHERE field REGEXP '^prefix'\";<\/pre>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<p>\u8be5\u67e5\u8be2\u5c06\u8fd4\u56de\u4ee5 &#8220;prefix&#8221; \u5f00\u5934\u7684\u884c\u3002<\/p>\n<p><strong>\u6848\u4f8b\uff1a\u67e5\u627e\u5305\u542b\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7684\u884c<\/strong><\/p>\n<p><strong>\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>$query = \"SELECT * FROM table WHERE field REGEXP '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}'\";<\/pre>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<p>\u8be5\u67e5\u8be2\u5c06\u8fd4\u56de\u5305\u542b\u6709\u6548\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7684\u884c\u3002<\/p>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ul>\n<li>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\u8981\u5c0f\u5fc3\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002<\/li>\n<li>\u907f\u514d\u8d2a\u5a6a\u91cf\u8bcd\uff08\u5982 <code>*<\/code> \u548c <code>+<\/code>\uff09\uff0c\u9664\u975e\u6709\u5fc5\u8981\u3002<\/li>\n<li>\u5728\u6570\u636e\u5e93\u67e5\u8be2\u4e2d\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\u8981\u5408\u7406\u5730\u8bbe\u7f6e\u7d22\u5f15\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aphp\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u914d\u5408\u4f7f\u7528\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8ephp,\u6570\u636e\u5e93\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u914d\u5408\u4f7f\u7528\uff1f \u4e00\u5206\u8015\u8018\uff0c\u4e00\u5206\u6536\u83b7\uff01\u65e2\u7136\u6253\u5f00\u4e86\u8fd9\u7bc7\u6587\u7ae0\u300aphp\u6b63\u5219\u8868\u8fbe\u5f0f\u5982\u4f55\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u914d\u5408\u4f7f\u7528\uff1f\u300b\uff0c\u5c31\u575a\u6301\u770b\u4e0b\u53bb\u5427\uff01\u6587\u4e2d\u5185\u5bb9\u5305\u542b\u7b49\u7b49\u77e5\u8bc6\u70b9&#8230;\u5e0c\u671b\u4f60\u80fd\u5728\u9605\u8bfb\u672c\u6587\u540e\uff0c\u80fd\u771f\u771f\u5b9e\u5b9e\u5b66\u5230\u77e5\u8bc6\u6216\u8005\u5e2e\u4f60\u89e3\u51b3\u5fc3\u4e2d\u7684\u7591\u60d1\uff0c\u4e5f\u6b22\u8fce\u5927\u4f6c\u6216\u8005\u65b0\u4eba\u670b\u53cb\u4eec\u591a\u7559\u8a00\u8bc4\u8bba\uff0c\u591a\u7ed9\u5efa\u8bae\uff01\u8c22\u8c22\uff01 PHP \u6b63\u5219\u8868\u8fbe\u5f0f\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u7684\u6574\u5408 PHP \u6b63\u5219\u8868\u8fbe\u5f0f\u63d0\u4f9b\u4e86\u4e00\u79cd\u5f3a\u5927\u7684\u65b9\u6cd5\u6765\u5339\u914d\u5b57\u7b26\u4e32\u6a21\u5f0f\u3002\u5b83\u53ef\u4ee5\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u76f8\u7ed3\u5408\uff0c\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u641c\u7d22\u548c\u7b5b\u9009\u529f\u80fd\u3002 \u8bed\u6cd5 \u4f7f\u7528 PHP \u4e2d\u7684 preg_match() \u51fd\u6570\u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u4e0e\u6570\u636e\u5e93\u67e5\u8be2\u76f8\u7ed3\u5408\uff1a preg_match($regex, $data) \u5176\u4e2d\uff1a $regex \u662f\u8981\u5339\u914d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f $data\u662f\u8981\u67e5\u8be2\u7684\u6570\u636e\uff08\u4f8b\u5982\uff0c\u6570\u636e\u5e93\u884c\u7684\u5185\u5bb9\uff09 \u5982\u679c\u6b63\u5219\u8868\u8fbe\u5f0f\u4e0e\u6570\u636e\u5339\u914d\uff0cpreg_match() \u5c06\u8fd4\u56de 1\u3002\u5426\u5219\uff0c\u5b83\u5c06\u8fd4\u56de 0\u3002 \u5b9e\u6218\u6848\u4f8b \u6848\u4f8b\uff1a\u67e5\u627e\u5305\u542b\u7279\u5b9a\u6570\u5b57\u7684\u884c \u4ee3\u7801\uff1a $query = &#8220;SELECT * FROM table WHERE field REGEXP &#8216;[0-9]+'&#8221;; \u7ed3\u679c\uff1a \u8be5\u67e5\u8be2\u5c06\u8fd4\u56de\u5305\u542b\u81f3\u5c11\u4e00\u4e2a\u6570\u5b57\u7684\u884c\u3002 \u6848\u4f8b\uff1a\u67e5\u627e\u4ee5\u7279\u5b9a\u524d\u7f00\u5f00\u5934\u7684\u884c \u4ee3\u7801\uff1a $query = &#8220;SELECT * FROM table WHERE field REGEXP &#8216;^prefix'&#8221;; \u7ed3\u679c\uff1a \u8be5\u67e5\u8be2\u5c06\u8fd4\u56de\u4ee5 &#8220;prefix&#8221; \u5f00\u5934\u7684\u884c\u3002 \u6848\u4f8b\uff1a\u67e5\u627e\u5305\u542b\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7684\u884c \u4ee3\u7801\uff1a [&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-46917","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46917","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=46917"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46917\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}