{"id":771,"date":"2024-11-07T15:52:48","date_gmt":"2024-11-07T07:52:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/771\/"},"modified":"2024-11-07T15:52:48","modified_gmt":"2024-11-07T07:52:48","slug":"php%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e8%bd%ac%e4%b9%89%e5%ad%97%e7%ac%a6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/771\/","title":{"rendered":"php\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u5982\u4f55\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\uff1f"},"content":{"rendered":"<p>\u8f6c\u4e49\u5b57\u7b26\u5728 php \u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7279\u5b9a\u5b57\u7b26\u5177\u6709\u7279\u6b8a\u542b\u4e49\uff0c\u4ece\u800c\u5339\u914d\u5b9e\u9645\u5b57\u7b26\u800c\u4e0d\u662f\u6267\u884c\u9884\u5b9a\u4e49\u64cd\u4f5c\u3002\u5e38\u7528\u7684\u8f6c\u4e49\u5b57\u7b26\u5305\u62ec\uff1a\uff1a\u5c4f\u853d\u7279\u6b8a\u5b57\u7b26\u7684\u539f\u59cb\u542b\u4e49.\uff1a\u5339\u914d\u9664\u6362\u884c\u7b26\u4e4b\u5916\u7684\u4efb\u4f55\u5b57\u7b26^\uff1a\u5339\u914d\u5b57\u7b26\u4e32\u5f00\u5934$\uff1a\u5339\u914d\u5b57\u7b26\u4e32\u7ed3\u5c3e*\uff1a\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u96f6\u6b21\u6216\u591a\u6b21+\uff1a\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u4e00\u6b21\u6216\u591a\u6b21?\uff1a\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u96f6\u6b21\u6216\u4e00\u6b21{}\uff1a\u6307\u5b9a\u5339\u914d\u5b57\u7b26\u7684\u6b21\u6570\u8303\u56f4[]\uff1a\u5339\u914d\u65b9\u62ec\u53f7\u4e2d\u6307\u5b9a\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26(): \u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u7ec4<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1135\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172846638275268.jpg\" width=\"720\" height=\"288\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172846638275268.jpg 720w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172846638275268-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172846638275268-670x268.jpg 670w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" title=\"php\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u5982\u4f55\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\uff1f\u63d2\u56fe\" alt=\"php\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u5982\u4f55\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u8f6c\u4e49\u5b57\u7b26<\/strong><\/p>\n<p>\u8f6c\u4e49\u5b57\u7b26\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7528\u4e8e\u4f7f\u7279\u5b9a\u5b57\u7b26\u5177\u6709\u7279\u6b8a\u542b\u4e49\u3002\u5b83\u4eec\u53ef\u8ba9\u60a8\u5728\u8868\u8fbe\u5f0f\u4e2d\u5339\u914d\u5b9e\u9645\u5b57\u7b26\uff0c\u800c\u4e0d\u662f\u5bf9\u5176\u6267\u884c\u9884\u5b9a\u4e49\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5e38\u7528\u7684\u8f6c\u4e49\u5b57\u7b26<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cPHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<table>\n<thead>\n<tr>\n<th>\u8f6c\u4e49\u5b57\u7b26<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><\/td>\n<td>\u5c4f\u853d\u7279\u6b8a\u5b57\u7b26\u7684\u539f\u59cb\u542b\u4e49<\/td>\n<\/tr>\n<tr>\n<td>.<\/td>\n<td>\u5339\u914d\u9664\u6362\u884c\u7b26\u4e4b\u5916\u7684\u4efb\u4f55\u5b57\u7b26<\/td>\n<\/tr>\n<tr>\n<td>^<\/td>\n<td>\u5339\u914d\u5b57\u7b26\u4e32\u5f00\u5934<\/td>\n<\/tr>\n<tr>\n<td>$<\/td>\n<td>\u5339\u914d\u5b57\u7b26\u4e32\u7ed3\u5c3e<\/td>\n<\/tr>\n<tr>\n<td>*<\/td>\n<td>\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u96f6\u6b21\u6216\u591a\u6b21<\/td>\n<\/tr>\n<tr>\n<td>+<\/td>\n<td>\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u4e00\u6b21\u6216\u591a\u6b21<\/td>\n<\/tr>\n<tr>\n<td>?<\/td>\n<td>\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u96f6\u6b21\u6216\u4e00\u6b21<\/td>\n<\/tr>\n<tr>\n<td>{}<\/td>\n<td>\u6307\u5b9a\u5339\u914d\u5b57\u7b26\u7684\u6b21\u6570\u8303\u56f4<\/td>\n<\/tr>\n<tr>\n<td>[]<\/td>\n<td>\u5339\u914d\u65b9\u62ec\u53f7\u4e2d\u6307\u5b9a\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26<\/td>\n<\/tr>\n<tr>\n<td>()<\/td>\n<td>\u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u7ec4<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3002\u8981\u5339\u914d\u6709\u6548\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a<\/p>\n<pre>$emailRegex = '\/^[w.-]+@[w.-]+.w{2,4}$\/';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u8868\u8fbe\u5f0f\u4f7f\u7528\u4ee5\u4e0b\u8f6c\u4e49\u5b57\u7b26\uff1a<\/p>\n<ul>\n<li>^\uff1a\u5339\u914d\u5b57\u7b26\u4e32\u5f00\u5934<\/li>\n<li>$\uff1a\u5339\u914d\u5b57\u7b26\u4e32\u7ed3\u5c3e<\/li>\n<li>w\uff1a\u5339\u914d\u4efb\u4f55\u5355\u8bcd\u5b57\u7b26\uff08\u5b57\u6bcd\u3001\u6570\u5b57\u6216\u4e0b\u5212\u7ebf\uff09<\/li>\n<li>.-\uff1a\u5339\u914d\u70b9\u53f7\u6216\u8fde\u5b57\u7b26<\/li>\n<li>@\uff1a\u5339\u914d\u5b9e\u9645\u7684 &#8220;@&#8221; \u5b57\u7b26<\/li>\n<li>+\uff1a\u8868\u793a w.- \u81f3\u5c11\u51fa\u73b0\u4e00\u6b21<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/p>\n<p>\u8981\u4f7f\u7528\u6b64\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u53ef\u4ee5\u6309\u4ee5\u4e0b\u65b9\u5f0f\u6267\u884c\uff1a<\/p>\n<pre>$email = 'example@domain.com';\n$matches = preg_match($emailRegex, $email);\n\nif ($matches &amp;gt; 0) {\n    echo '\u6709\u6548\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740';\n} else {\n    echo '\u65e0\u6548\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740';\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u8f6c\u4e49\u5b57\u7b26\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u8ba9\u60a8\u5339\u914d\u5b9e\u9645\u5b57\u7b26\u5e76\u521b\u5efa\u590d\u6742\u7684\u8868\u60c5\u3002\u4e86\u89e3\u548c\u4f7f\u7528\u5b83\u4eec\u5bf9\u4e8e\u9ad8\u6548\u800c\u51c6\u786e\u5730\u5904\u7406\u6587\u672c\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fphp\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u5982\u4f55\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u4e49\u5b57\u7b26\u5728 php \u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u4f7f\u7279\u5b9a\u5b57\u7b26\u5177\u6709\u7279\u6b8a\u542b\u4e49\uff0c\u4ece\u800c\u5339\u914d\u5b9e\u9645\u5b57\u7b26\u800c\u4e0d\u662f\u6267\u884c\u9884\u5b9a\u4e49\u64cd\u4f5c\u3002\u5e38\u7528\u7684\u8f6c\u4e49\u5b57\u7b26\u5305\u62ec\uff1a\uff1a\u5c4f\u853d\u7279\u6b8a\u5b57\u7b26\u7684\u539f\u59cb\u542b\u4e49.\uff1a\u5339\u914d\u9664\u6362\u884c\u7b26\u4e4b\u5916\u7684\u4efb\u4f55\u5b57\u7b26^\uff1a\u5339\u914d\u5b57\u7b26\u4e32\u5f00\u5934$\uff1a\u5339\u914d\u5b57\u7b26\u4e32\u7ed3\u5c3e*\uff1a\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u96f6\u6b21\u6216\u591a\u6b21+\uff1a\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u4e00\u6b21\u6216\u591a\u6b21?\uff1a\u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u96f6\u6b21\u6216\u4e00\u6b21{}\uff1a\u6307\u5b9a\u5339\u914d\u5b57\u7b26\u7684\u6b21\u6570\u8303\u56f4[]\uff1a\u5339\u914d\u65b9\u62ec\u53f7\u4e2d\u6307\u5b9a\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26(): \u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u7ec4 PHP \u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7684\u8f6c\u4e49\u5b57\u7b26 \u8f6c\u4e49\u5b57\u7b26\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u7528\u4e8e\u4f7f\u7279\u5b9a\u5b57\u7b26\u5177\u6709\u7279\u6b8a\u542b\u4e49\u3002\u5b83\u4eec\u53ef\u8ba9\u60a8\u5728\u8868\u8fbe\u5f0f\u4e2d\u5339\u914d\u5b9e\u9645\u5b57\u7b26\uff0c\u800c\u4e0d\u662f\u5bf9\u5176\u6267\u884c\u9884\u5b9a\u4e49\u64cd\u4f5c\u3002 \u5e38\u7528\u7684\u8f6c\u4e49\u5b57\u7b26 \u7acb\u5373\u5b66\u4e60\u201cPHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b \u8f6c\u4e49\u5b57\u7b26 \u63cf\u8ff0 \u5c4f\u853d\u7279\u6b8a\u5b57\u7b26\u7684\u539f\u59cb\u542b\u4e49 . \u5339\u914d\u9664\u6362\u884c\u7b26\u4e4b\u5916\u7684\u4efb\u4f55\u5b57\u7b26 ^ \u5339\u914d\u5b57\u7b26\u4e32\u5f00\u5934 $ \u5339\u914d\u5b57\u7b26\u4e32\u7ed3\u5c3e * \u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u96f6\u6b21\u6216\u591a\u6b21 + \u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u4e00\u6b21\u6216\u591a\u6b21 ? \u5339\u914d\u524d\u9762\u7684\u5b57\u7b26\u96f6\u6b21\u6216\u4e00\u6b21 {} \u6307\u5b9a\u5339\u914d\u5b57\u7b26\u7684\u6b21\u6570\u8303\u56f4 [] \u5339\u914d\u65b9\u62ec\u53f7\u4e2d\u6307\u5b9a\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26 () \u5c06\u6b63\u5219\u8868\u8fbe\u5f0f\u5206\u7ec4 \u5b9e\u6218\u6848\u4f8b \u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5176\u4e2d\u5305\u542b\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u3002\u8981\u5339\u914d\u6709\u6548\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a $emailRegex = &#8216;\/^[w.-]+@[w.-]+.w{2,4}$\/&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u8868\u8fbe\u5f0f\u4f7f\u7528\u4ee5\u4e0b\u8f6c\u4e49\u5b57\u7b26\uff1a ^\uff1a\u5339\u914d\u5b57\u7b26\u4e32\u5f00\u5934 $\uff1a\u5339\u914d\u5b57\u7b26\u4e32\u7ed3\u5c3e w\uff1a\u5339\u914d\u4efb\u4f55\u5355\u8bcd\u5b57\u7b26\uff08\u5b57\u6bcd\u3001\u6570\u5b57\u6216\u4e0b\u5212\u7ebf\uff09 .-\uff1a\u5339\u914d\u70b9\u53f7\u6216\u8fde\u5b57\u7b26 @\uff1a\u5339\u914d\u5b9e\u9645\u7684 &#8220;@&#8221; \u5b57\u7b26 +\uff1a\u8868\u793a w.- \u81f3\u5c11\u51fa\u73b0\u4e00\u6b21 \u4f7f\u7528\u793a\u4f8b \u8981\u4f7f\u7528\u6b64\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u53ef\u4ee5\u6309\u4ee5\u4e0b\u65b9\u5f0f\u6267\u884c\uff1a $email = &#8216;example@domain.com&#8217;; $matches = preg_match($emailRegex, [&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-771","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/771","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=771"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/771\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}