{"id":466,"date":"2010-06-25T09:11:26","date_gmt":"2010-06-25T09:11:26","guid":{"rendered":""},"modified":"2010-06-25T09:11:26","modified_gmt":"2010-06-25T09:11:26","slug":"466","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=466","title":{"rendered":"PHP\u5f00\u53d1\u4eba\u5458\u5bb9\u6613\u5ffd\u7565\u7684\u51e0\u70b9\u7cbe\u534e"},"content":{"rendered":"<p><strong>1\u3001\u53d8\u91cf\u3001\u6570\u7ec4\u7684\u5e94\u7528\u6280\u5de7<\/strong><\/p>\n<p>(1)\u5f88\u591a\u4eba\u7528\u5f97\u4e0d\u591a\u7684\u6570\u7ec4\u51fd\u6570\u3002foreach\u3001list\u3001each\u3002\u5206\u522b\u4e3e\u51e0\u4e2a\u4f8b\u5b50\uff0c\u5e94\u8be5\u5c31\u80fd\u77e5\u9053\u4e86\u3002\u4f8b\uff1a<\/p>\n<p><code><br \/>$data = array(\u2018a\u2019 =&gt; \u2018data1\u2032, \u2018b\u2019 =&gt; \u2018data2\u2032, \u2018c\u2019 =&gt; \u2018data3\u2032);&nbsp;&nbsp;<br \/>while(list($subscript, $value) = each($data))&nbsp;&nbsp;{&nbsp;&nbsp;<br \/>echo \u201c$subscript =&gt; $value :: \u201c;&nbsp;&nbsp;<br \/>echo \u201c$subscript =&gt; $value<br \/>\n\u201d;&nbsp;&nbsp;<br \/>}&nbsp;&nbsp;<br \/>reset($data);&nbsp;&nbsp;<br \/>foreach($data as $subscript =&gt; $value)&nbsp;&nbsp;{&nbsp;&nbsp;<br \/>echo \u201c$subscript =&gt; $value :: \u201c;&nbsp;&nbsp;<br \/>echo \u201c$subscript =&gt; $value<br \/>\n&nbsp;&nbsp;\u201c;&nbsp;&nbsp;<br \/>} <br \/><\/code><\/p>\n<p>(2)\u51fd\u6570\u7684\u53d8\u91cf\u3001\u53d8\u91cf\u7684\u53d8\u91cf\u3001\u53d8\u91cf\u7684\u201c\u6307\u9488\u201d\uff1a\u770b\u4e0b\u4f8b\uff1a<\/p>\n<p><code><br \/>\/\/\u53d8\u91cf\u7684\u53d8\u91cf&nbsp;&nbsp;<br \/>$var = \u201cthis is a var\u201d;&nbsp;&nbsp;<br \/>$varname = \u201cvar\u201d;&nbsp;&nbsp;<br \/>echo $$varname;&nbsp;&nbsp; <br \/>\/\/\u51fd\u6570\u7684\u53d8\u91cf&nbsp;&nbsp;<br \/>function fun1($str) {&nbsp;&nbsp;<br \/>echo $str;&nbsp;&nbsp;<br \/>}&nbsp;&nbsp;<br \/>$funname = \u201cfun1\u2033;&nbsp;&nbsp;<br \/>$funname(\u201cThis is a function !\u201d);&nbsp;&nbsp;<br \/>?&gt; <br \/><\/code><\/p>\n<p>\u53d8\u91cf\u7684\u201c\u6307\u9488\u201d\u3002\u8fd9\u4e2a\u6307\u9488\u52a0\u4e0a\u4e86\u53cc\u5f15\u53f7\uff0c\u8868\u660e\u4ed6\u4e0d\u662f\u771f\u6b63\u7684\u6307\u9488\u3002\u770b\u770b\u4e0b\u4f8b\uff1a<\/p>\n<p><code><br \/>function($a) {&nbsp;&nbsp;<br \/>$a ++;&nbsp;&nbsp;<br \/>}&nbsp;&nbsp;<br \/>$c = 0;&nbsp;&nbsp;<br \/>function($c);&nbsp;&nbsp;<br \/>echo $c; \/\/$c\u4ecd\u4e3a0&nbsp;&nbsp;<br \/>function(&$a) {&nbsp;&nbsp;<br \/>$a ++;&nbsp;&nbsp;<br \/>}&nbsp;&nbsp;<br \/>$c = 0;&nbsp;&nbsp;<br \/>echo $c; \/\/$c\u4e3a1&nbsp;&nbsp;<br \/>?&gt; <br \/><\/code><br \/>\u4e4b\u6240\u4ee5\u79f0\u5176\u4e3a\u201c\u6307\u9488\u201d\uff0c\u5c31\u662f\u56e0\u4e3a\u4ed6\u6709\u4e86\u548cC\u8bed\u8a00\u4e2d\u6307\u9488\u76f8\u540c\u7684\u529f\u80fd\u3002\u4f46\u8fd9\u53c8\u4e0d\u662f\u771f\u6b63\u7684\u6307\u9488\uff0c\u53ea\u80fd\u591f\u662f\u8fd9\u6837\u7684\u53bb\u7406\u89e3\u3002<\/p>\n<p><strong>2\u3001\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u4e00\u4e2a\u975e\u5e38\u5927\u7684\u9898\u76ee\uff0cPerl\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5f3a\u5927\u662f\u95fb\u4e86\u540d\u7684\u3002\u800cPHP\u4e5f\u4e0d\u5f31\uff0c\u4ed6\u7ee7\u627f\u4e86Perl\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u6cd5\u5219\uff0c\u8fd8\u6709\u81ea\u5df1\u7684\u4e00\u5957\u6cd5\u5219\u3002\u8fd9\u91cc\u53ea\u8bf4PHP\u81ea\u5df1\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u6700\u57fa\u672c\u7684\u5143\u7d20\u3002\u7b80\u5355\u5730\u8bf4\u5c31\u662f\u4e00\u5957\u89c4\u5219\uff0c\u7528\u4e8e\u53bb\u5224\u5b9a\u5176\u5b83\u7684\u5143\u7d20\u662f\u4e0d\u662f\u7b26\u5408\u81ea\u8eab\u7684\u89c4\u5219\uff0c\u6216\u8005\u8bf4\u662f\u4e0d\u662f\u6709\u76f8\u540c\u7684\u7279\u5f81\u63cf\u8ff0\u3002<\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5f00\u59cb\u7b26\uff1a^\uff0c\u7ed3\u5c3e\u7b26$\uff0c\u8fd9\u4e24\u4e2a\u7b26\u53f7\u95f4\u7684\u662f\u5339\u914d\u7684\u5143\u7d20\u3002\u5982\u68c0\u67e5\u4e00\u4e2a\u7535\u8bdd\u53f7\u7801\u662f\u4e0d\u662f\u6253\u5f80\u5317\u4eac\u7684\u53f7\uff0c\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u8868\u793a\u5c31\u662f \u201c^010$\u201d\u3002\u53ea\u8981\u524d3\u4f4d\u533a\u53f7\u662f010\uff0c\u5c31\u662f\u5317\u4eac\u7684\u53f7\uff0c\u540e\u9762\u7684\u7535\u8bdd\u53f7\u7801\u5c31\u4e0d\u7528\u7ba1\u4e86\u3002\u7136\u540e\uff0c\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\u51fd\u6570ereg\u6765\u5224\u65ad\uff0c\u4f8b\uff1a<\/p>\n<p><code><br \/>$pattern = \u201c^010$\u201d;&nbsp;&nbsp;<br \/>$phone = \u201c01080718828\u2033;&nbsp;&nbsp;<br \/>if(ereg($pattern, $phone))&nbsp;&nbsp;<br \/>echo \u201c\u6253\u5f80\u5317\u4eac\u7684\u53f7\u201d;&nbsp;&nbsp;<br \/>else&nbsp;&nbsp;<br \/>echo \u201c\u4e0d\u662f\u6253\u5f80\u5317\u4eac\u7684\u53f7\u201d;&nbsp;&nbsp;<br \/>?&gt; <br \/><\/code><\/p>\n<p>\u8fd9\u5c31\u662f\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u5317\u4eac\u7684\u7535\u8bdd\u90fd\u662f8\u4f4d\u6570\u5b57\u7684\uff0c\u90a3\u6211\u8981\u77e5\u9053\u8fd9\u4e2a\u53f7\u7801\u662f\u4e0d\u662f\u6b63\u786e\u4e86?\u5047\u5982\u4ed6\u6309\u4e869\u4f4d\u53f7\u5462?\u5982\u679c\u5224\u65ad\u6b63\u8bef?\u8fd9\u5c31\u8981\u7528\u5230\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5b57\u7b26\u7c07\u3002\u90a3\u4e48\u4e0a\u4f8b\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u5c31\u8981\u8fd9\u6837\u5199\uff1a^010[0-9]{8}$\uff0c\u5c31\u80fd\u540c\u65f6\u5224\u65ad\u53f7\u7801\u662f\u4e0d\u662f\u7b26\u5408\u89c4\u5219\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u6709\u5f88\u591a\u7684\u5e94\u7528\uff0c\u50cfLBB\u3001VBB\u8bba\u575b\u5728\u53d1\u8d34\u65f6\u7684\u6240\u8c13VBB\u4ee3\u7801LBB\u4ee3\u7801\u7684\u89e3\u6790\uff0c\u90fd\u662f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5b8c\u6210\u7684\u3002<\/p>\n<p><strong>3\u3001\u6a21\u677f<\/strong><\/p>\n<p>\u77e5\u9053\u4e86\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u529f\u80fd\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u77e5\u9053\u6a21\u677f\u4e86\u3002\u4ec0\u4e48\u662f\u6a21\u677f?\u4e3e\u4e2a\u4f8b\u5b50\u5427?\u4e00\u822c\u5199\u7f51\u9875\u7528\u5230\u4e86\u540e\u53f0\u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u90fd\u662f\u5728\u7f51\u9875\u91cc\u9762\u63d2\u5165\u7a0b\u5e8f\u4ee3\u7801\u3002\u5982 PHP\u3002\u8fd9\u5c31\u662fHTML\u548cPHP\u7684\u6df7\u5199\u3002\u8fd9\u6837\u7684\u4f18\u70b9\u662f\u8bfb\u53d6\u901f\u5ea6\u5feb\uff0c\u7f3a\u70b9\u662f\u5982\u679c\u5927\u5bb6\u5206\u5de5\u5408\u4f5c\u505a\u7f51\u7ad9\uff0c\u90a3\u4e48\u975e\u7a0b\u5e8f\u5458\u5c31\u4e0d\u4f1a\u6539\u7f51\u4e86\u3002<\/p>\n<p>\u800c\u7528\u6a21\u677f\uff0c\u5219\u53ef\u4ee5\u8fbe\u5230\u5206\u5de5\u7684\u6700\u5408\u7406\u5316\u3002\u7f8e\u5de5\u53ea\u505a\u9875\u9762\uff0c\u7a0b\u5e8f\u53ea\u5199\u540e\u53f0\uff0c\u7136\u540e\u518d\u5408\u8d77\u6765\u3002\u4f18\u79c0\u7684Jsp\u63d0\u4f9b\u4e86\u81ea\u5b9a\u4e49\u6807\u7b7e\u7684\u529f\u80fd\u5f88\u597d\u5730\u5b8c\u6210\u4e86\u6a21\u677f\u529f\u80fd\u3002\u800c\u4e3b\u6d41\u7684PHP\u5982\u4f55\u505a\u5230\u5462?\u5c31\u662f\u5229\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u505a\u5230\u7684\u3002\u53ef\u4ee5\u53bb\u7f51\u4e0a\u4e0b\u8f7d\u4e00\u4e2aPHPLIB\uff0c\u91cc\u9762\u7684PHP\u76ee\u5f55\u4e0b\u6709\u4e00\u4e2atemplate.inc\u7684\u6e90\u4ee3\u7801\u6587\u4ef6\uff0c\u90a3\u5c31\u662f\u7528PHP\u5b9e\u73b0\u6a21\u677f\u5957\u7528\u7684\u7c7b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u53d8\u91cf\u3001\u6570\u7ec4\u7684\u5e94\u7528\u6280\u5de7 (1)\u5f88\u591a\u4eba\u7528\u5f97\u4e0d\u591a\u7684\u6570\u7ec4\u51fd\u6570\u3002forea&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-466","post","type-post","status-publish","format-standard","hentry","category-Php"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=466"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/466\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}