{"id":804,"date":"2025-10-24T15:04:38","date_gmt":"2025-10-24T07:04:38","guid":{"rendered":"https:\/\/www.youvii.site\/?p=804"},"modified":"2025-10-24T15:09:28","modified_gmt":"2025-10-24T07:09:28","slug":"phpjichu-2","status":"publish","type":"post","link":"https:\/\/www.youvii.site\/index.php\/archives\/phpjichu-2","title":{"rendered":"PHP\u57fa\u7840"},"content":{"rendered":"<h1>PHP\u57fa\u7840<\/h1>\n<h1>\u6982\u8ff0<\/h1>\n<p>PHP\uff08\u5168\u79f0\uff1aPHP\uff1aHypertext Preprocessor\uff0c\u5373&quot;PHP\uff1a\u8d85\u6587\u672c\u9884\u5904\u7406\u5668&quot;\uff09\u662f\u4e00\u79cd<\/p>\n<p>\u901a\u7528\u5f00\u6e90\u811a\u672c\u8bed\u8a00\u3002<\/p>\n<p>\u5728\u4e00\u4e2a php \u6587\u4ef6\u4e2d\u53ef\u4ee5\u5305\u62ec\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<p>PHP \u6587\u4ef6\u53ef\u5305\u542b\u6587\u672c\u3001HTML\u3001JavaScript \u4ee3\u7801\u548c PHP \u4ee3\u7801<\/p>\n<p>PHP \u4ee3\u7801\u5728\u670d\u52a1\u5668\u4e0a\u6267\u884c\uff0c\u7ed3\u679c\u4ee5\u7eaf HTML \u5f62\u5f0f\u8fd4\u56de\u7ed9\u6d4f\u89c8\u5668<\/p>\n<p>PHP \u6587\u4ef6\u7684\u9ed8\u8ba4\u6587\u4ef6\u6269\u5c55\u540d\u662f &quot;.php&quot;<\/p>\n<p>php \u7684\u4f7f\u7528\uff1a<\/p>\n<ol>\n<li>\n<p>PHP \u53ef\u4ee5\u751f\u6210\u52a8\u6001\u9875\u9762\u5185\u5bb9<\/p>\n<\/li>\n<li>\n<p>PHP \u53ef\u4ee5\u521b\u5efa\u3001\u6253\u5f00\u3001\u8bfb\u53d6\u3001\u5199\u5165\u3001\u5173\u95ed\u670d\u52a1\u5668\u4e0a\u7684\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>PHP \u53ef\u4ee5\u6536\u96c6\u8868\u5355\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>PHP \u53ef\u4ee5\u53d1\u9001\u548c\u63a5\u6536 cookies<\/p>\n<\/li>\n<li>\n<p>PHP \u53ef\u4ee5\u6dfb\u52a0\u3001\u5220\u9664\u3001\u4fee\u6539\u60a8\u7684\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>PHP \u53ef\u4ee5\u9650\u5236\u7528\u6237\u8bbf\u95ee\u60a8\u7684\u7f51\u7ad9\u4e0a\u7684\u4e00\u4e9b\u9875\u9762<\/p>\n<\/li>\n<li>\n<p>PHP \u53ef\u4ee5\u52a0\u5bc6\u6570\u636e<\/p>\n<\/li>\n<\/ol>\n<h1>\u57fa\u672c\u8bed\u6cd5<\/h1>\n<p>PHP \u811a\u672c\u4ee5 &lt;?php \u5f00\u59cb\uff0c\u4ee5 ?&gt; \u7ed3\u675f<\/p>\n<p>&lt;?php<\/p>\n<p>\/\/php \u811a\u672c\u7684\u57fa\u672c\u683c\u5f0f<\/p>\n<p>\/*<\/p>\n<ul>\n<li>\n<p>\u591a\u884c\u6ce8\u91ca\uff0c\u8ddf java \u7684\u6ce8\u91ca\u65b9\u6cd5\u76f8\u540c<\/p>\n<\/li>\n<li>\n<p>*\/<\/p>\n<\/li>\n<\/ul>\n<h2>\u53d8\u91cf\u7684\u547d\u540d<\/h2>\n<p>\u53d8\u91cf\u4ee5 $ \u7b26\u53f7\u5f00\u59cb\uff0c\u540e\u9762\u8ddf\u7740\u53d8\u91cf\u7684\u540d\u79f0<\/p>\n<p>\u53d8\u91cf\u540d\u5fc5\u987b\u4ee5\u5b57\u6bcd\u6216\u8005\u4e0b\u5212\u7ebf\u5b57\u7b26\u5f00\u59cb<\/p>\n<p>\u53d8\u91cf\u540d\u53ea\u80fd\u5305\u542b\u5b57\u6bcd\u6570\u5b57\u5b57\u7b26\u4ee5\u53ca\u4e0b\u5212\u7ebf\uff08A-z\u30010-9 \u548c _ \uff09<\/p>\n<p>\u53d8\u91cf\u540d\u4e0d\u80fd\u5305\u542b\u7a7a\u683c<\/p>\n<p>\/\/php \u7684\u53d8\u91cf\u58f0\u660e\u662f\u4ee5$\u5f00\u59cb\u7684<\/p>\n<p>$num = 3.14;<\/p>\n<p>$str = &quot;hello&quot;;<\/p>\n<p><strong>\u5173\u952e\u5b57<\/strong><\/p>\n<p>\/*static \u7684\u5173\u952e\u5b57\u7684\u4f7f\u7528<\/p>\n<ul>\n<li>\n<p>\u5f53\u4e00\u4e2a\u51fd\u6570\u5b8c\u6210\u65f6\uff0c\u5b83\u7684\u6240\u6709\u53d8\u91cf\u901a\u5e38\u90fd\u4f1a\u88ab\u5220\u9664\u3002<\/p>\n<\/li>\n<li>\n<p>\u7136\u800c\uff0c\u6709\u65f6\u5019\u60a8\u5e0c\u671b\u67d0\u4e2a\u5c40\u90e8\u53d8\u91cf\u4e0d\u8981\u88ab\u5220\u9664\u3002<\/p>\n<\/li>\n<li>\n<p>\u8981\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u8bf7\u5728\u60a8\u7b2c\u4e00\u6b21\u58f0\u660e\u53d8\u91cf\u65f6\u4f7f\u7528 static \u5173\u952e\u5b57\uff1a<\/p>\n<\/li>\n<li>\n<p>*\/<\/p>\n<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">function test(){\nstatic $n=0;\n$n++;\necho \"\u8c03\u7528\u4e86\u4e00\u6b21\".$n.\"n\";\n}\ntest();test();test();\n?&gt;<\/code><\/pre>\n<h2>\u6570\u636e\u7c7b\u578b\u3001\u5e38\u91cf\u53ca\u5b57\u7b26\u4e32<\/h2>\n<p>php \u6709 5 \u79cd\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<p>String\uff08\u5b57\u7b26\u4e32\uff09, Integer\uff08\u6574\u578b\uff09, Float\uff08\u6d6e\u70b9\u578b\uff09,<\/p>\n<p>Boolean\uff08\u5e03\u5c14\u578b\uff09, Array\uff08\u6570\u7ec4\uff09, Object\uff08\u5bf9\u8c61\uff09, NULL\uff08\u7a7a\u503c\uff09\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$a = \"\u5b57\u7b26\u4e32\u7c7b\u578b\";\n$b = 1234;\/\/\u6574\u5f62\n$c = -3.1415;\/\/\u6d6e\u70b9\u578b\n$d = 8E-3;\n$e = true;\/\/boolean \u7c7b\u578b\n$f = array(\"A\",\"B\",\"C\");\/\/\u6570\u7ec4\u7c7b\u578b\nclass obj{\/\/php \u5bf9\u8c61\u7684\u58f0\u660e\nvar $num;\nfunction name() { }\n}\n$o = new obj();\/\/\u5bf9\u8c61\u5b9e\u4f8b\u5316\u7c7b\u578b\n$g = NULL;\/\/NULL\nvar_dump($a);var_dump($b);var_dump($c);var_dump($d);\nvar_dump($e);var_dump($f);var_dump($o);var_dump($g);\n?&gt;<\/code><\/pre>\n<p>\u5e38\u91cf\uff1a\u5e38\u91cf\u662f\u4e00\u4e2a\u7b80\u5355\u503c\u7684\u6807\u8bc6\u7b26\u3002\u8be5\u503c\u5728\u811a\u672c\u4e2d\u4e0d\u80fd\u6539\u53d8\u3002\uff08\u5728\u6574\u4e2a\u811a\u672c\u4e2d\u90fd<\/p>\n<p>\u80fd\u4f7f\u7528\uff09<\/p>\n<p>\u4e00\u4e2a\u5e38\u91cf\u7531\u82f1\u6587\u5b57\u6bcd\u3001\u4e0b\u5212\u7ebf\u3001\u548c\u6570\u5b57\u7ec4\u6210,\u4f46\u6570\u5b57\u4e0d\u80fd\u4f5c\u4e3a\u9996\u5b57\u6bcd\u51fa\u73b0\u3002 (\u5e38\u91cf<\/p>\n<p>\u540d\u4e0d\u9700\u8981\u52a0 $ \u4fee\u9970\u7b26)\u3002<\/p>\n<p>\u8bbe\u7f6e\u5e38\u91cf\uff0c\u4f7f\u7528 define() \u51fd\u6570\uff0c\u51fd\u6570\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>bool define ( string $name , mixed $value [, bool $case_insensitive = false ] )<\/p>\n<p>\u8be5\u51fd\u6570\u6709\u4e09\u4e2a\u53c2\u6570:<\/p>\n<p>name\uff1a\u5fc5\u9009\u53c2\u6570\uff0c\u5e38\u91cf\u540d\u79f0\uff0c\u5373\u6807\u5fd7\u7b26\u3002<\/p>\n<p>value\uff1a\u5fc5\u9009\u53c2\u6570\uff0c\u5e38\u91cf\u7684\u503c\u3002<\/p>\n<p>case_insensitive \uff1a\u53ef\u9009\u53c2\u6570\uff0c\u5982\u679c\u8bbe\u7f6e\u4e3a TRUE\uff0c\u8be5\u5e38\u91cf\u5219\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u3002\u9ed8<\/p>\n<p>\u8ba4\u662f\u5927\u5c0f\u5199\u654f\u611f\u7684\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n\/\/ \u5e38\u91cf\ndefine(\"CL\", \"\u8fd9\u662f\u4e00\u4e2a\u5168\u5c40\u5e38\u91cf\", true);\necho CL; \/\/ \u9ed8\u8ba4 false\uff0c\u53d8\u91cf\u540d\u533a\u5206\u5927\u5c0f\u5199\necho cl; \/\/ true \u4e0d\u533a\u5206\u5927\u5c0f\u5199\n?&gt;<\/code><\/pre>\n<h3>\u9884\u5b9a\u4e49\u5e38\u91cf<\/h3>\n<p>PHP \u9884\u5b9a\u4e49\u4e86\u8bb8\u591a\u5e38\u91cf\uff0c\u8fd9\u4e9b\u5e38\u91cf\u65e0\u9700\u4f7f\u7528 define()\u51fd\u6570\u5b9a\u4e49\uff0c\u53ef\u76f4\u63a5\u5728\u7a0b\u5e8f\u4e2d<\/p>\n<p>\u4f7f\u7528\u3002\u4e0b\u9762\u5217\u4e3e\u4e86\u4e00\u4e9b\u5e38\u7528\u7684 PHP \u9884\u5b9a\u4e49\u5e38\u91cf\u3002<\/p>\n<p>\uff081\uff09<strong>FILE<\/strong>(FILE \u524d\u540e\u5206\u522b\u662f\u4e24\u4e2a\u4e0b\u753b\u7ebf)\uff1a\u5f53\u524d\u6b63\u5728\u5904\u7406\u7684\u811a\u672c\u6587\u4ef6\u540d\uff0c\u82e5<\/p>\n<p>\u4f7f\u7528\u5728\u4e00\u4e2a\u88ab\u5f15\u7528\u7684\u6587\u4ef6\u4e2d\uff08include \u6216 require\uff09\uff0c\u90a3\u4e48 \u5b83\u7684\u503c\u5c31\u662f\u88ab\u5f15\u7528<\/p>\n<p>\u7684\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u5f15\u7528\u5b83\u7684\u90a3\u4e2a\u6587\u4ef6\u3002<\/p>\n<p>\uff082\uff09<strong>LINE<\/strong>(LINE \u524d\u540e\u5206\u522b\u662f\u4e24\u4e2a\u4e0b\u753b\u7ebf)\uff1a\u6b63\u5728\u5904\u7406\u7684\u811a\u672c\u6587\u4ef6\u7684\u5f53\u524d\u884c\u6570\u3002<\/p>\n<p>\uff083\uff09PHP_VERSION\uff1a\u5f53\u524d PHP \u9884\u5904\u7406\u5668\u7684\u7248\u672c\uff0c\u5982 5.4.16\u3002<\/p>\n<p>\uff084\uff09PHP_OS: PHP \u6240\u5728\u7684\u64cd\u4f5c\u7cfb\u7edf\u7684\u7c7b\u578b\u3002\u5982 Linux\u3002<\/p>\n<p>\uff085\uff09TRUE\uff1a\u8868\u793a\u903b\u8f91\u771f\u3002FALSE\uff1a\u8868\u793a\u903b\u8f91\u5047\u3002NULL\uff1a\u8868\u793a\u6ca1\u6709\u503c\u6216\u503c\u4e0d\u786e<\/p>\n<p>\u5b9a\u3002<\/p>\n<p>\uff086\uff09DIRECTORY_SEPARATOR: \u8868\u793a\u76ee\u5f55\u5206\u9694\u7b26\uff0cUNIX \u6216 Linux \u64cd\u4f5c\u7cfb\u7edf\u73af<\/p>\n<p>\u5883\u65f6\u7684\u503c\u4e3a\u201c \/ \u201d, Window \u64cd\u4f5c\u7cfb\u7edf\u73af\u5883\u65f6\u7684\u503c\u4e3a \u201c  \u201d\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\necho __FILE__;\necho \"&lt;br\/&gt;\";\necho __LINE__;\necho \"&lt;br\/&gt;\";\necho PHP_VERSION;\necho \"&lt;br\/&gt;\";\necho PHP_OS;\necho \"&lt;br\/&gt;\";\necho DIRECTORY_SEPARATOR;\n?&gt;<\/code><\/pre>\n<h3>\u6574\u578b<\/h3>\n<p>\u6574\u6570\u7c7b\u578b\uff1a\u4fdd\u5b58\u6574\u6570\u6570\u503c\uff08\u8303\u56f4\u9650\u5236\uff09\uff0c4 \u4e2a\u5b57\u8282\u5b58\u50a8\u6570\u636e\u3002PHP \u4e2d\u9ed8\u8ba4\u4e3a\u6709\u7b26<\/p>\n<p>\u53f7\u3002<\/p>\n<p>\u5728 PHP \u4e2d\u63d0\u4f9b\u56db\u79cd\u6574\u5f62\u7684\u5b9a\u4e49\u65b9\u5f0f\uff0c\u5341\u8fdb\u5236\u5b9a\u4e49\uff0c\u4e8c\u8fdb\u5236\u5b9a\u4e49\uff0c\u516b\u8fdb\u5236\u5b9a\u4e49\u548c<\/p>\n<p>\u5341\u516d\u8fdb\u5236\u5b9a\u4e49<\/p>\n<p>$a = 120 \/\/\u5341\u8fdb\u5236<\/p>\n<p>$a = 0b110 \/\/\u4e8c\u8fdb\u5236<\/p>\n<p>$a = 0120 \/\/\u516b\u8fdb\u5236<\/p>\n<p>$a = 0x120 \/\/\u5341\u516d\u8fdb\u5236<\/p>\n<p>\/\/ \u4f7f\u7528 echo \u8f93\u51fa\u65f6\u3002\u9ed8\u8ba4\u8f93\u51fa\u4e3a\u5341\u8fdb\u5236<\/p>\n<p>decbin() \/\/ \u5341\u8fdb\u5236\u8f6c\u4e8c\u8fdb\u5236<\/p>\n<p>decoct() \/\/ \u5341\u8fdb\u5236\u8f6c\u516b\u8fdb\u5236<\/p>\n<p>dechex() \/\/ \u5341\u8fdb\u5236\u8f6c\u5341\u516d\u8fdb\u5236<\/p>\n<p>bindec() \/\/ \u4e8c\u8fdb\u5236\u8f6c\u5341\u8fdb\u5236<\/p>\n<p>bin2hex() \/\/\u4e8c\u8fdb\u5236\u8f6c\u5341\u516d\u8fdb\u5236<\/p>\n<h3>\u5b57\u7b26\u4e32<\/h3>\n<p>\u5b57\u7b26\u4e32\u53d8\u91cf\u7528\u4e8e\u5b58\u50a8\u5e76\u5904\u7406\u6587\u672c\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$name='yuhui';\n\/\/\u53cc\u5f15\u53f7 \u91cc\u9762\u6709\u53d8\u91cf \u4f1a \u8f93\u51fa\u53d8\u91cf\u7684\u503c\n$str =\"\u8fd9\u662f $name \u7684\u5168\u6808\u6e17\u900f\u6d4b\u8bd5\u57f9\u8bad\uff0c\u8fd9\u662f\u4e00\u4e2a\u6bd4\u8f83\u9ad8\u8d28\u91cf\u7684\u8bfe\u7a0b\uff0c\u4e00\u4e2a\u5f88\n\u5927\u7684\u4f53\u7cfb \u6b22\u8fce\u6765\u5b66\u4e60\u3002\";\n\/\/\u5355\u5f15\u53f7 \u5982\u679c\u91cc\u9762\u6709\u53d8\u91cf\u90fd\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5904\u7406\n$str1 ='\u8fd9\u662f $name \u7684\u5168\u6808\u6e17\u900f\u6d4b\u8bd5\u57f9\u8bad\uff0c\u8fd9\u662f\u4e00\u4e2a\u6bd4\u8f83\u9ad8\u8d28\u91cf\u7684\u8bfe\u7a0b\uff0c\u4e00\u4e2a\u5f88\n\u5927\u7684\u4f53\u7cfb \u6b22\u8fce\u6765\u5b66\u4e60\u3002';\necho $str;\necho $str1;\n&lt;?php\n\/\/ \u5b57\u7b26\u4e32\n$text1 = \"hello\";\n$text2 = \"world\";\necho $text1 . \" \" . $text2; \/\/ \".\"\u662f\u5e76\u7f6e\u8fd0\u7b97\u7b26\uff08\u8fde\u63a5\uff09\necho \"\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff1a\", strlen($text1);\necho \"\u8fd4\u56de\u5b50\u4e32\u7684\u7b2c\u4e00\u6b21\u4f4d\u7f6e\uff1a\", strpos($text1, \"l\");\n?&gt;<\/code><\/pre>\n<p>\u5b57\u7b26\u7684\u64cd\u4f5c\u51fd\u6570<\/p>\n<p>addcslashes \u2014 \u4ee5 C \u8bed\u8a00\u98ce\u683c\u4f7f\u7528\u53cd\u659c\u7ebf\u8f6c\u4e49\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26<\/p>\n<p>addslashes \u2014 \u4f7f\u7528\u53cd\u659c\u7ebf\u5f15\u7528\u5b57\u7b26\u4e32<\/p>\n<p>bin2hex \u2014 \u51fd\u6570\u628a\u5305\u542b\u6570\u636e\u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u503c<\/p>\n<p>chop \u2014 rtrim \u7684\u522b\u540d<\/p>\n<p>chr \u2014 \u8fd4\u56de\u6307\u5b9a\u7684\u5b57\u7b26<\/p>\n<p>chunk_split \u2014 \u5c06\u5b57\u7b26\u4e32\u5206\u5272\u6210\u5c0f\u5757<\/p>\n<p>convert_cyr_string \u2014 \u5c06\u5b57\u7b26\u7531\u4e00\u79cd Cyrillic \u5b57\u7b26\u8f6c\u6362\u6210\u53e6\u4e00\u79cd<\/p>\n<p>convert_uudecode \u2014 \u89e3\u7801\u4e00\u4e2a uuencode \u7f16\u7801\u7684\u5b57\u7b26\u4e32<\/p>\n<p>convert_uuencode \u2014 \u4f7f\u7528 uuencode \u7f16\u7801\u4e00\u4e2a\u5b57\u7b26\u4e32<\/p>\n<p>count_chars \u2014 \u8fd4\u56de\u5b57\u7b26\u4e32\u6240\u7528\u5b57\u7b26\u7684\u4fe1\u606f<\/p>\n<p>crc32 \u2014 \u8ba1\u7b97\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684 crc32 \u591a\u9879\u5f0f<\/p>\n<p>crypt \u2014 \u5355\u5411\u5b57\u7b26\u4e32\u6563\u5217<\/p>\n<p>echo \u2014 \u8f93\u51fa\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u4e32<\/p>\n<p>explode \u2014 \u4f7f\u7528\u4e00\u4e2a\u5b57\u7b26\u4e32\u5206\u5272\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32<\/p>\n<p>fprintf \u2014 \u5c06\u683c\u5f0f\u5316\u540e\u7684\u5b57\u7b26\u4e32\u5199\u5165\u5230\u6d41<\/p>\n<p>get_html_translation_table \u2014 \u8fd4\u56de\u4f7f\u7528 htmlspecialchars \u548c htmlentities \u540e\u7684\u8f6c\u6362<\/p>\n<p>\u8868<\/p>\n<p>hebrev \u2014 \u5c06\u903b\u8f91\u987a\u5e8f\u5e0c\u4f2f\u6765\u6587\uff08logical-Hebrew\uff09\u8f6c\u6362\u4e3a\u89c6\u89c9\u987a\u5e8f\u5e0c\u4f2f\u6765\u6587<\/p>\n<p>\uff08visual-Hebrew\uff09<\/p>\n<p>hebrevc \u2014 \u5c06\u903b\u8f91\u987a\u5e8f\u5e0c\u4f2f\u6765\u6587\uff08logical-Hebrew\uff09\u8f6c\u6362\u4e3a\u89c6\u89c9\u987a\u5e8f\u5e0c\u4f2f\u6765\u6587<\/p>\n<p>\uff08visual-Hebrew\uff09\uff0c\u5e76\u4e14\u8f6c\u6362\u6362\u884c\u7b26<\/p>\n<p>hex2bin \u2014 \u8f6c\u6362\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\u4e3a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32<\/p>\n<p>html_entity_decode \u2014 Convert HTML entities to their corresponding characters<\/p>\n<p>htmlentities \u2014 \u5c06\u5b57\u7b26\u8f6c\u6362\u4e3a HTML \u8f6c\u4e49\u5b57\u7b26<\/p>\n<p>htmlspecialchars_decode \u2014 \u5c06\u7279\u6b8a\u7684 HTML \u5b9e\u4f53\u8f6c\u6362\u56de\u666e\u901a\u5b57\u7b26<\/p>\n<p>htmlspecialchars \u2014 \u5c06\u7279\u6b8a\u5b57\u7b26\u8f6c\u6362\u4e3a HTML \u5b9e\u4f53<\/p>\n<p>implode \u2014 \u5c06\u4e00\u4e2a\u4e00\u7ef4\u6570\u7ec4\u7684\u503c\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32<\/p>\n<p>join \u2014 \u522b\u540d implode<\/p>\n<p>lcfirst \u2014 \u4f7f\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5c0f\u5199<\/p>\n<p>levenshtein \u2014 \u8ba1\u7b97\u4e24\u4e2a\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u7f16\u8f91\u8ddd\u79bb<\/p>\n<p>localeconv \u2014 Get numeric formatting information<\/p>\n<p>ltrim \u2014 \u5220\u9664\u5b57\u7b26\u4e32\u5f00\u5934\u7684\u7a7a\u767d\u5b57\u7b26\uff08\u6216\u5176\u4ed6\u5b57\u7b26\uff09<\/p>\n<p>md5_file \u2014 \u8ba1\u7b97\u6307\u5b9a\u6587\u4ef6\u7684 MD5 \u6563\u5217\u503c<\/p>\n<p>md5 \u2014 \u8ba1\u7b97\u5b57\u7b26\u4e32\u7684 MD5 \u6563\u5217\u503c<\/p>\n<p>metaphone \u2014 Calculate the metaphone key of a string<\/p>\n<p>money_format \u2014 \u5c06\u6570\u5b57\u683c\u5f0f\u5316\u6210\u8d27\u5e01\u5b57\u7b26\u4e32<\/p>\n<p>nl_langinfo \u2014 Query language and locale information<\/p>\n<p>nl2br \u2014 \u5728\u5b57\u7b26\u4e32\u6240\u6709\u65b0\u884c\u4e4b\u524d\u63d2\u5165 HTML \u6362\u884c\u6807\u8bb0<\/p>\n<p>number_format \u2014 \u4ee5\u5343\u4f4d\u5206\u9694\u7b26\u65b9\u5f0f\u683c\u5f0f\u5316\u4e00\u4e2a\u6570\u5b57<\/p>\n<p>ord \u2014 \u8f6c\u6362\u5b57\u7b26\u4e32\u7b2c\u4e00\u4e2a\u5b57\u8282\u4e3a 0-255 \u4e4b\u95f4\u7684\u503c<\/p>\n<p>parse_str \u2014 \u5c06\u5b57\u7b26\u4e32\u89e3\u6790\u6210\u591a\u4e2a\u53d8\u91cf<\/p>\n<p>print \u2014 \u8f93\u51fa\u5b57\u7b26\u4e32<\/p>\n<p>printf \u2014 \u8f93\u51fa\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/p>\n<p>quoted_printable_decode \u2014 \u5c06 quoted-printable \u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a 8-bit \u5b57\u7b26\u4e32<\/p>\n<p>quoted_printable_encode \u2014 \u5c06 8-bit \u5b57\u7b26\u4e32\u8f6c\u6362\u6210 quoted-printable \u5b57\u7b26\u4e32<\/p>\n<p>quotemeta \u2014 \u8f6c\u4e49\u5143\u5b57\u7b26\u96c6<\/p>\n<p>rtrim \u2014 \u5220\u9664\u5b57\u7b26\u4e32\u672b\u7aef\u7684\u7a7a\u767d\u5b57\u7b26\uff08\u6216\u8005\u5176\u4ed6\u5b57\u7b26\uff09<\/p>\n<p>setlocale \u2014 \u8bbe\u7f6e\u5730\u533a\u4fe1\u606f<\/p>\n<p>sha1_file \u2014 \u8ba1\u7b97\u6587\u4ef6\u7684 sha1 \u6563\u5217\u503c<\/p>\n<p>sha1 \u2014 \u8ba1\u7b97\u5b57\u7b26\u4e32\u7684 sha1 \u6563\u5217\u503c<\/p>\n<p>similar_text \u2014 \u8ba1\u7b97\u4e24\u4e2a\u5b57\u7b26\u4e32\u7684\u76f8\u4f3c\u5ea6<\/p>\n<p>soundex \u2014 Calculate the soundex key of a string<\/p>\n<p>sprintf \u2014 Return a formatted string<\/p>\n<p>sscanf \u2014 \u6839\u636e\u6307\u5b9a\u683c\u5f0f\u89e3\u6790\u8f93\u5165\u7684\u5b57\u7b26<\/p>\n<p>str_contains \u2014 Determine if a string contains a given substring<\/p>\n<p>str_ends_with \u2014 Checks if a string ends with a given substring<\/p>\n<p>str_getcsv \u2014 \u89e3\u6790 CSV \u5b57\u7b26\u4e32\u4e3a\u4e00\u4e2a\u6570\u7ec4<\/p>\n<p>str_ireplace \u2014 str_replace \u7684\u5ffd\u7565\u5927\u5c0f\u5199\u7248\u672c<\/p>\n<p>str_pad \u2014 \u4f7f\u7528\u53e6\u4e00\u4e2a\u5b57\u7b26\u4e32\u586b\u5145\u5b57\u7b26\u4e32\u4e3a\u6307\u5b9a\u957f\u5ea6<\/p>\n<p>str_repeat \u2014 \u91cd\u590d\u4e00\u4e2a\u5b57\u7b26\u4e32<\/p>\n<p>str_replace \u2014 \u5b50\u5b57\u7b26\u4e32\u66ff\u6362<\/p>\n<p>str_rot13 \u2014 \u5bf9\u5b57\u7b26\u4e32\u6267\u884c ROT13 \u8f6c\u6362<\/p>\n<p>str_shuffle \u2014 \u968f\u673a\u6253\u4e71\u4e00\u4e2a\u5b57\u7b26\u4e32<\/p>\n<p>str_split \u2014 \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u7ec4<\/p>\n<p>str_starts_with \u2014 Checks if a string starts with a given substring<\/p>\n<p>str_word_count \u2014 \u8fd4\u56de\u5b57\u7b26\u4e32\u4e2d\u5355\u8bcd\u7684\u4f7f\u7528\u60c5\u51b5<\/p>\n<p>strcasecmp \u2014 \u4e8c\u8fdb\u5236\u5b89\u5168\u6bd4\u8f83\u5b57\u7b26\u4e32\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09<\/p>\n<p>strchr \u2014 \u522b\u540d strstr<\/p>\n<p>strcmp \u2014 \u4e8c\u8fdb\u5236\u5b89\u5168\u5b57\u7b26\u4e32\u6bd4\u8f83<\/p>\n<p>strcoll \u2014 \u57fa\u4e8e\u533a\u57df\u8bbe\u7f6e\u7684\u5b57\u7b26\u4e32\u6bd4\u8f83<\/p>\n<p>strcspn \u2014 \u83b7\u53d6\u4e0d\u5339\u914d\u906e\u7f69\u7684\u8d77\u59cb\u5b50\u5b57\u7b26\u4e32\u7684\u957f\u5ea6<\/p>\n<p>strip_tags \u2014 \u4ece\u5b57\u7b26\u4e32\u4e2d\u53bb\u9664 HTML \u548c PHP \u6807\u8bb0<\/p>\n<p>stripcslashes \u2014 \u53cd\u5f15\u7528\u4e00\u4e2a\u4f7f\u7528 addcslashes \u8f6c\u4e49\u7684\u5b57\u7b26\u4e32<\/p>\n<p>stripos \u2014 \u67e5\u627e\u5b57\u7b26\u4e32\u9996\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09<\/p>\n<p>stripslashes \u2014 \u53cd\u5f15\u7528\u4e00\u4e2a\u5f15\u7528\u5b57\u7b26\u4e32<\/p>\n<p>stristr \u2014 strstr \u51fd\u6570\u7684\u5ffd\u7565\u5927\u5c0f\u5199\u7248\u672c<\/p>\n<p>strlen \u2014 \u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6<\/p>\n<p>strnatcasecmp \u2014 \u4f7f\u7528\u201c\u81ea\u7136\u987a\u5e8f\u201d\u7b97\u6cd5\u6bd4\u8f83\u5b57\u7b26\u4e32\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09<\/p>\n<p>strnatcmp \u2014 \u4f7f\u7528\u81ea\u7136\u6392\u5e8f\u7b97\u6cd5\u6bd4\u8f83\u5b57\u7b26\u4e32<\/p>\n<p>strncasecmp \u2014 \u4e8c\u8fdb\u5236\u5b89\u5168\u6bd4\u8f83\u5b57\u7b26\u4e32\u5f00\u5934\u7684\u82e5\u5e72\u4e2a\u5b57\u7b26\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09<\/p>\n<p>strncmp \u2014 \u4e8c\u8fdb\u5236\u5b89\u5168\u6bd4\u8f83\u5b57\u7b26\u4e32\u5f00\u5934\u7684\u82e5\u5e72\u4e2a\u5b57\u7b26<\/p>\n<p>strpbrk \u2014 \u5728\u5b57\u7b26\u4e32\u4e2d\u67e5\u627e\u4e00\u7ec4\u5b57\u7b26\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26<\/p>\n<p>strpos \u2014 \u67e5\u627e\u5b57\u7b26\u4e32\u9996\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e<\/p>\n<p>strrchr \u2014 \u67e5\u627e\u6307\u5b9a\u5b57\u7b26\u5728\u5b57\u7b26\u4e32\u4e2d\u7684\u6700\u540e\u4e00\u6b21\u51fa\u73b0<\/p>\n<p>strrev \u2014 \u53cd\u8f6c\u5b57\u7b26\u4e32<\/p>\n<p>strripos \u2014 \u8ba1\u7b97\u6307\u5b9a\u5b57\u7b26\u4e32\u5728\u76ee\u6807\u5b57\u7b26\u4e32\u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\uff08\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff09<\/p>\n<p>strrpos \u2014 \u8ba1\u7b97\u6307\u5b9a\u5b57\u7b26\u4e32\u5728\u76ee\u6807\u5b57\u7b26\u4e32\u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e<\/p>\n<p>strspn \u2014 \u8ba1\u7b97\u5b57\u7b26\u4e32\u4e2d\u5168\u90e8\u5b57\u7b26\u90fd\u5b58\u5728\u4e8e\u6307\u5b9a\u5b57\u7b26\u96c6\u5408\u4e2d\u7684\u7b2c\u4e00\u6bb5\u5b50\u4e32\u7684\u957f\u5ea6\u3002<\/p>\n<p>strstr \u2014 \u67e5\u627e\u5b57\u7b26\u4e32\u7684\u9996\u6b21\u51fa\u73b0<\/p>\n<p>strtok \u2014 \u6807\u8bb0\u5206\u5272\u5b57\u7b26\u4e32<\/p>\n<p>strtolower \u2014 \u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u5c0f\u5199<\/p>\n<p>strtoupper \u2014 \u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u5927\u5199<\/p>\n<p>strtr \u2014 \u8f6c\u6362\u6307\u5b9a\u5b57\u7b26<\/p>\n<p>substr_compare \u2014 \u4e8c\u8fdb\u5236\u5b89\u5168\u6bd4\u8f83\u5b57\u7b26\u4e32\uff08\u4ece\u504f\u79fb\u4f4d\u7f6e\u6bd4\u8f83\u6307\u5b9a\u957f\u5ea6\uff09<\/p>\n<p>substr_count \u2014 \u8ba1\u7b97\u5b57\u4e32\u51fa\u73b0\u7684\u6b21\u6570<\/p>\n<p>substr_replace \u2014 \u66ff\u6362\u5b57\u7b26\u4e32\u7684\u5b50\u4e32<\/p>\n<p>substr \u2014 \u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u5b50\u4e32<\/p>\n<p>trim \u2014 \u53bb\u9664\u5b57\u7b26\u4e32\u9996\u5c3e\u5904\u7684\u7a7a\u767d\u5b57\u7b26\uff08\u6216\u8005\u5176\u4ed6\u5b57\u7b26\uff09<\/p>\n<p>ucfirst \u2014 \u5c06\u5b57\u7b26\u4e32\u7684\u9996\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199<\/p>\n<p>ucwords \u2014 \u5c06\u5b57\u7b26\u4e32\u4e2d\u6bcf\u4e2a\u5355\u8bcd\u7684\u9996\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5927\u5199<\/p>\n<p>vfprintf \u2014 \u5c06\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u5199\u5165\u6d41<\/p>\n<p>vprintf \u2014 \u8f93\u51fa\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/p>\n<p>vsprintf \u2014 \u8fd4\u56de\u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/p>\n<p>wordwrap \u2014 \u6253\u65ad\u5b57\u7b26\u4e32\u4e3a\u6307\u5b9a\u6570\u91cf\u7684\u5b57\u4e32<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$name='yuhui';\n\/\/\u53cc\u5f15\u53f7 \u91cc\u9762\u6709\u53d8\u91cf \u4f1a \u8f93\u51fa\u53d8\u91cf\u7684\u503c\n\/\/$str =\" \u8fd9\u662f $name \u7684\u5168\u6808\u6e17\u900f\u6d4b\u8bd5\u57f9\u8bad\uff0c\u8fd9\u662f\u4e00\u4e2a\u6bd4\u8f83\u9ad8\u8d28\u91cf\u7684\u8bfe\u7a0b\uff0c\u4e00\u4e2a\n\u5f88\u5927\u7684\u4f53\u7cfb \u6b22\u8fce\u6765\u5b66\u4e60\u3002 \";\n\/\/\u5355\u5f15\u53f7 \u5982\u679c\u91cc\u9762\u6709\u53d8\u91cf\u90fd\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5904\u7406\n\/\/$str1 ='\u8fd9\u662f $name \u7684\u5168\u6808\u6e17\u900f\u6d4b\u8bd5\u57f9\u8bad\uff0c\u8fd9\u662f\u4e00\u4e2a\u6bd4\u8f83\u9ad8\u8d28\u91cf\u7684\u8bfe\u7a0b\uff0c\u4e00\u4e2a\n\u5f88\u5927\u7684\u4f53\u7cfb \u6b22\u8fce\u6765\u5b66\u4e60\u3002';\n$a='123456';\n\/\/echo $str.\" \u4e00\u5171\u6709 \".strlen($a).\"\u5b57\u7b26\";\n\/\/\u53bb\u6389\u7a7a\u683c\n\/\/echo trim($str);\n\/\/echo $str1;\n\/\/\u67e5\u627e\u5b57\u7b26\u4e32 \u8fd4\u56de\u4f4d\u7f6e\n\/\/echo strpos($str,'yuhui');\n\/\/\u622a\u53d6\u5b57\u7b26\u4e32\n\/\/echo substr($str,strpos($str,'yuhui'),strpos($str,'\u57f9\u8bad'));\n\/\/md5 \u52a0\u5bc6\n\/\/echo md5($a);\n\/\/\u901a\u8fc7\u4e0b\u6807 \u53d6\u5b57\u7b26\u7684\u503c\n\/\/echo $a[0];\n\/\/\u5b57\u7b26\u4e32\u66ff\u6362\u51fd\u6570\n$a1=str_replace('1','0',$a);\necho $a1;\n\/\/\u904d\u5386\u5b57\u7b26\u4e32\nfor($i=0;$i&lt;=strlen($a);$i++){\necho $a[$i].'&lt;\/br&gt;';\n}\nfunction mb_str_split( $string ) {\n\/\/ \/u \u8868\u793a\u628a\u5b57\u7b26\u4e32\u5f53\u4f5c utf-8 \u5904\u7406\uff0c\u5e76\u628a\u5b57\u7b26\u4e32\u5f00\u59cb\u548c\u7ed3\u675f\u4e4b\u524d\u6240\u6709\u7684\u5b57\u7b26\n\u4e32\u5206\u5272\u6210\u6570\u7ec4\nreturn preg_split('\/(?&lt;!^)(?!$)\/u', $string );\n}\nfor($i=0;$i&lt;strlen($str);$i++) {\n$k = $str[$i]; \/\/\u8f93\u51fa\u4e71\u7801\n}\nforeach (mb_str_split($str) as $c)\n{\necho $c; \/\/\u6b63\u5e38\u8f93\u51fa\uff1a\u4e2d \u6587 \u6d4b \u8bd5\n}<\/code><\/pre>\n<h1>\u8fd0\u7b97\u7b26<\/h1>\n<div class=\"table-responsive\"><table class=\"table\" >\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u8fd0\u7b97\u7b26<\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u793a\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u7b97\u672f\u8fd0\u7b97\u7b26<\/td>\n<td>+<\/td>\n<td>\u52a0\u6cd5\u3002\u7528\u4e8e\u6570\u503c\u76f8\u52a0\u6216\u5b57\u7b26\u4e32\u8fde\u63a5\u3002<\/td>\n<td><code>5 + 3<\/code> \u7ed3\u679c\u4e3a 8; <code>\"Hello\" . \" World\"<\/code> \u7ed3\u679c\u4e3a &quot;Hello World&quot;<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&#8211;<\/td>\n<td>\u51cf\u6cd5\u3002\u7528\u4e8e\u6570\u503c\u51cf\u6cd5\u3002<\/td>\n<td><code>10 - 4<\/code> \u7ed3\u679c\u4e3a 6<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>*<\/td>\n<td>\u4e58\u6cd5\u3002\u7528\u4e8e\u6570\u503c\u76f8\u4e58\u3002<\/td>\n<td><code>7 * 6<\/code> \u7ed3\u679c\u4e3a 42<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>\/<\/td>\n<td>\u9664\u6cd5\u3002\u8fd4\u56de\u6d6e\u70b9\u6570\u7ed3\u679c\u3002<\/td>\n<td><code>10 \/ 2<\/code> \u7ed3\u679c\u4e3a 5.0<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>%<\/td>\n<td>\u53d6\u6a21\uff08\u53d6\u4f59\uff09\u3002<\/td>\n<td><code>10 % 3<\/code> \u7ed3\u679c\u4e3a 1<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>**<\/td>\n<td>\u5e42\u3002\u5c06\u5de6\u4fa7\u7684\u64cd\u4f5c\u6570\u63d0\u5347\u5230\u53f3\u4fa7\u64cd\u4f5c\u6570\u6307\u5b9a\u7684\u5e42\u3002<\/td>\n<td><code>2 ** 3<\/code> \u7ed3\u679c\u4e3a 8<\/td>\n<\/tr>\n<tr>\n<td>\u6bd4\u8f83\u8fd0\u7b97\u7b26<\/td>\n<td>==<\/td>\n<td>\u76f8\u7b49\u3002\u68c0\u67e5\u4e24\u4e2a\u503c\u662f\u5426\u76f8\u7b49\u3002<\/td>\n<td><code>5 == 5<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>===<\/td>\n<td>\u5168\u7b49\u3002\u68c0\u67e5\u4e24\u4e2a\u503c\u662f\u5426\u76f8\u7b49\u4e14\u7c7b\u578b\u76f8\u540c\u3002<\/td>\n<td><code>5 === \"5\"<\/code> \u7ed3\u679c\u4e3a false<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>!= \u6216 &lt;&gt;<\/td>\n<td>\u4e0d\u7b49\u4e8e\u3002\u68c0\u67e5\u4e24\u4e2a\u503c\u662f\u5426\u4e0d\u76f8\u7b49\u3002<\/td>\n<td><code>5 != 4<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>!==<\/td>\n<td>\u4e0d\u5168\u7b49\u3002\u68c0\u67e5\u4e24\u4e2a\u503c\u662f\u5426\u4e0d\u76f8\u7b49\u6216\u7c7b\u578b\u4e0d\u540c\u3002<\/td>\n<td><code>5 !== \"5\"<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&lt;<\/td>\n<td>\u5c0f\u4e8e\u3002<\/td>\n<td><code>3 &lt; 5<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&gt;<\/td>\n<td>\u5927\u4e8e\u3002<\/td>\n<td><code>7 &gt; 5<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&lt;=<\/td>\n<td>\u5c0f\u4e8e\u7b49\u4e8e\u3002<\/td>\n<td><code>5 &lt;= 5<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>&gt;=<\/td>\n<td>\u5927\u4e8e\u7b49\u4e8e\u3002<\/td>\n<td><code>5 &gt;= 5<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td>\u903b\u8f91\u8fd0\u7b97\u7b26<\/td>\n<td>&amp;&amp;<\/td>\n<td>\u4e0e\u3002\u5f53\u4e24\u8fb9\u90fd\u4e3a\u771f\u65f6\u8fd4\u56detrue\u3002<\/td>\n<td><code>true &amp;&amp; false<\/code> \u7ed3\u679c\u4e3a false<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>!<\/td>\n<td>\u975e\u3002\u53cd\u8f6c\u5e03\u5c14\u503c\u3002<\/td>\n<td><code>!true<\/code> \u7ed3\u679c\u4e3a false<\/td>\n<\/tr>\n<tr>\n<td>\u5b57\u7b26\u4e32\u8fd0\u7b97\u7b26<\/td>\n<td>.<\/td>\n<td>\u4e32\u8054\u3002\u5c06\u4e24\u4e2a\u5b57\u7b26\u4e32\u5408\u5e76\u6210\u4e00\u4e2a\u65b0\u5b57\u7b26\u4e32\u3002<\/td>\n<td><code>\"Hi\" . \" there\"<\/code> \u7ed3\u679c\u4e3a &quot;Hi there&quot;<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u7ec4\u8fd0\u7b97\u7b26<\/td>\n<td>+<\/td>\n<td>\u8054\u5408\u3002\u5408\u5e76\u4e24\u4e2a\u6570\u7ec4\uff0c\u4f46\u4e0d\u4fdd\u7559\u91cd\u590d\u9879\u3002<\/td>\n<td><code>$a = [1, 2]; $b = [2, 3]; $a + $b<\/code> \u7ed3\u679c\u4e3a <code>[1, 2]<\/code><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>==<\/td>\n<td>\u5224\u65ad\u4e24\u4e2a\u6570\u7ec4\u662f\u5426\u62e5\u6709\u76f8\u540c\u7684\u952e\u503c\u5bf9\u3002<\/td>\n<td><code>array(1, 2) == array(1, 2)<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>===<\/td>\n<td>\u5224\u65ad\u4e24\u4e2a\u6570\u7ec4\u662f\u5426\u5b8c\u5168\u76f8\u540c\uff08\u5305\u62ec\u952e\u540d\u3001\u952e\u503c\u53ca\u987a\u5e8f\uff09\u3002<\/td>\n<td><code>array(1, 2) === array(1, 2)<\/code> \u7ed3\u679c\u4e3a true<\/td>\n<\/tr>\n<tr>\n<td>\u6761\u4ef6\u8fd0\u7b97\u7b26<\/td>\n<td>? :<\/td>\n<td>\u4e09\u5143\u6761\u4ef6\u8fd0\u7b97\u7b26\u3002\u6839\u636e\u6761\u4ef6\u9009\u62e9\u6267\u884c\u7684\u7ed3\u679c\u3002<\/td>\n<td><code>(5 &gt; 3) ? \"Yes\" : \"No\"<\/code> \u7ed3\u679c\u4e3a &quot;Yes&quot;<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<h1>\u63a7\u5236\u8bed\u53e5<\/h1>\n<p>\u63a7\u5236\u8bed\u6cd5\u7684\u8bed\u53e5\u7ed3\u6784\u548c\u5176\u4ed6\u5927\u591a\u6570\u8bed\u8a00\u7ed3\u6784\u76f8\u540c\uff0c\u6709\u4ee5\u4e0b\u4e24\u7c7b\uff1a<\/p>\n<h2>\u6761\u4ef6\u63a7\u5236\u8bed\u53e5<\/h2>\n<p>if \u8bed\u53e5 &#8211; \u5728\u6761\u4ef6\u6210\u7acb\u65f6\u6267\u884c\u4ee3\u7801<\/p>\n<p>if&#8230;else \u8bed\u53e5 &#8211; \u5728\u6761\u4ef6\u6210\u7acb\u65f6\u6267\u884c\u4e00\u5757\u4ee3\u7801\uff0c\u6761\u4ef6\u4e0d\u6210\u7acb\u65f6\u6267\u884c\u53e6\u4e00\u5757\u4ee3\u7801<\/p>\n<p>if&#8230;elseif&#8230;.else \u8bed\u53e5 &#8211; \u5728\u82e5\u5e72\u6761\u4ef6\u4e4b\u4e00\u6210\u7acb\u65f6\u6267\u884c\u4e00\u4e2a\u4ee3\u7801\u5757<\/p>\n<p>switch \u8bed\u53e5 &#8211; \u5728\u82e5\u5e72\u6761\u4ef6\u4e4b\u4e00\u6210\u7acb\u65f6\u6267\u884c\u4e00\u4e2a\u4ee3\u7801\u5757<\/p>\n<h2>\u5faa\u73af\u63a7\u5236\u8bed\u53e5<\/h2>\n<p>while &#8211; \u53ea\u8981\u6307\u5b9a\u7684\u6761\u4ef6\u6210\u7acb\uff0c\u5219\u5faa\u73af\u6267\u884c\u4ee3\u7801\u5757<\/p>\n<p>do&#8230;while &#8211; \u9996\u5148\u6267\u884c\u4e00\u6b21\u4ee3\u7801\u5757\uff0c\u7136\u540e\u5728\u6307\u5b9a\u7684\u6761\u4ef6\u6210\u7acb\u65f6\u91cd\u590d\u8fd9\u4e2a\u5faa\u73af<\/p>\n<p>for &#8211; \u5faa\u73af\u6267\u884c\u4ee3\u7801\u5757\u6307\u5b9a\u7684\u6b21\u6570<\/p>\n<p>foreach &#8211; \u6839\u636e\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u5143\u7d20\u6765\u5faa\u73af\u4ee3\u7801\u5757<\/p>\n<p>break \u8bed\u53e5\u7528\u4e8e\u7ec8\u6b62\u672c\u6b21\u5faa\u73af<\/p>\n<p>continue \u8bed\u53e5\u7684\u4f5c\u7528\u662f\u8df3\u51fa\u672c\u6b21\u5faa\u73af\uff0c\u63a5\u7740\u6267\u884c\u4e0b\u4e00\u6b21\u5faa\u73af<\/p>\n<h1>php\u6570\u7ec4<\/h1>\n<p>\u6570\u7ec4\u662f\u4e00\u4e2a\u80fd\u5728\u5355\u4e2a\u53d8\u91cf\u4e2d\u5b58\u50a8\u591a\u4e2a\u503c\u7684\u7279\u6b8a\u53d8\u91cf\u3002<\/p>\n<p>\u5728 PHP \u4e2d\uff0carray() \u51fd\u6570\u7528\u4e8e\u521b\u5efa\u6570\u7ec4\uff1a<\/p>\n<p>array();<\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u6709\u4e09\u79cd\u7c7b\u578b\u7684\u6570\u7ec4\uff1a<\/p>\n<p>\u6570\u503c\u6570\u7ec4 &#8211; \u5e26\u6709\u6570\u5b57 ID \u952e\u7684\u6570\u7ec4<\/p>\n<p>\u5173\u8054\u6570\u7ec4 &#8211; \u5e26\u6709\u6307\u5b9a\u7684\u952e\u7684\u6570\u7ec4\uff0c\u6bcf\u4e2a\u952e\u5173\u8054\u4e00\u4e2a\u503c<\/p>\n<p>\u591a\u7ef4\u6570\u7ec4 &#8211; \u5305\u542b\u4e00\u4e2a\u6216\u591a\u4e2a\u6570\u7ec4\u7684\u6570\u7ec4<\/p>\n<p>\u6570\u7ec4\u7684\u58f0\u660e<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">$array1 = array();\n&lt;?php\n$cars=array(\"Volvo\",\"BMW\",\"Toyota\");\/\/\u7b80\u5355\u7684\u6570\u7ec4\necho count($cars);\/\/count()\u8fd4\u56de\u6570\u7ec4\u7684\u957f\u5ea6\n$age=array(\"Peter\"=&gt;\"35\",\"Ben\"=&gt;\"37\",\"Joe\"=&gt;\"43\");\/\/\u5173\u8054\u6570\u7ec4\n\/\/\u5176\u4e2d\u5305\u542b\u591a\u4e2a\u952e\u503c\u5bf9\necho \"Peter is \" . $age['Peter'] . \" years old.\";\nforeach($age as $x=&gt;$x_value)\/\/\u5173\u8054\u6570\u7ec4\u7684\u904d\u5386\u65b9\u6cd5\n{\necho \"Key=\" . $x . \", Value=\" . $x_value;\necho \"&lt;br&gt;\";\n}\n?&gt;<\/code><\/pre>\n<p>\u5728 PHP \u4e2d\u5b9a\u4e49\u4e86\u591a\u4e2a\u6570\u7ec4\u6392\u5e8f\u7684\u5185\u7f6e\u51fd\u6570\uff1a<\/p>\n<p>sort() &#8211; \u5bf9\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5217<\/p>\n<p>rsort() &#8211; \u5bf9\u6570\u7ec4\u8fdb\u884c\u964d\u5e8f\u6392\u5217<\/p>\n<p>asort() &#8211; \u6839\u636e\u5173\u8054\u6570\u7ec4\u7684\u503c\uff0c\u5bf9\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5217<\/p>\n<p>ksort() &#8211; \u6839\u636e\u5173\u8054\u6570\u7ec4\u7684\u952e\uff0c\u5bf9\u6570\u7ec4\u8fdb\u884c\u5347\u5e8f\u6392\u5217<\/p>\n<p>arsort() &#8211; \u6839\u636e\u5173\u8054\u6570\u7ec4\u7684\u503c\uff0c\u5bf9\u6570\u7ec4\u8fdb\u884c\u964d\u5e8f\u6392\u5217<\/p>\n<p>krsort() &#8211; \u6839\u636e\u5173\u8054\u6570\u7ec4\u7684\u952e\uff0c\u5bf9\u6570\u7ec4\u8fdb\u884c\u964d\u5e8f\u6392\u5217<\/p>\n<h2>\u6570\u7ec4\u7684\u64cd\u4f5c<\/h2>\n<h3>\u6570\u7ec4\u7684\u5408\u62fc<\/h3>\n<p>$array1 =array(&#8216;a&#8217;,&#8217;b&#8217;,&#8217;c&#8217;);<\/p>\n<p>$array2 = array(&#8216;a1&#8217;=&gt;&#8217;php&#8217;,&#8217;a2&#8217;=&gt;&#8217;python&#8217;,&#8217;a3&#8217;=&gt;&#8217;java&#8217;);<\/p>\n<p>$array3 = array_merge($array1,$array2);<\/p>\n<h3>\u586b\u52a0\u6570\u7ec4\u5143\u7d20<\/h3>\n<p>array_push() \u51fd\u6570\u5411\u7b2c\u4e00\u4e2a\u53c2\u6570\u7684\u6570\u7ec4\u5c3e\u90e8\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u5143\u7d20\uff08\u5165\u6808\uff09\uff0c\u7136\u540e<\/p>\n<p>\u8fd4\u56de\u65b0\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/p>\n<p>array_push($array1,&#8217;d&#8217;,&#8217;e&#8217;);<\/p>\n<p>print_r($array1);<\/p>\n<p>\u4e0b\u8868\u4e3a\u7a7a \u81ea\u52a8\u6dfb\u52a0\u53c2\u6570<\/p>\n<p>$array1[]=&#8217;d&#8217;;<\/p>\n<p>\u6709\u952e\u503c\u7684<\/p>\n<p>$array1[&#8216;a4&#8242;]=&#8217;javasciprt&#8217;;<\/p>\n<h3>\u6dfb\u52a0\u5230\u6307\u5b9a\u4f4d\u7f6e<\/h3>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$array1 = array('a', 'b', 'c', 'd', 'e');\n$array2 = array('x');\narray_splice($array1, 3, 0, $array2); \/\/ \u63d2\u5165\u5230\u4f4d\u7f6e 3 \u4e14\u5220\u9664 0 \u4e2a\nprint_r($array1);\n?&gt;<\/code><\/pre>\n<p>array_splice(\u6570\u7ec4\uff0c\u4f4d\u7f6e\uff0c\u5220\u9664\u51e0\u4e2a\uff0c\u589e\u52a0\u5143\u7d20\uff09<\/p>\n<p>\u5220\u9664\u67d0\u4e00\u4e2a\u5143\u7d20<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$array1 = array('a', 'b', 'c', 'd', 'e');\n$array2 = array('x');\narray_splice($array1, 3, 1);\nprint_r($array1);\n?&gt;<\/code><\/pre>\n<p>unset \u9500\u6bc1\u6307\u5b9a\u7684\u5143\u7d20<\/p>\n<p>$array1 = array(&#8216;a&#8217;, &#8216;b&#8217;, &#8216;c&#8217;, &#8216;d&#8217;, &#8216;e&#8217;);<\/p>\n<p>unset($array1[0]);<\/p>\n<p>print_r($array1);<\/p>\n<p>array_pop():\u5c06\u6570\u7ec4\u6700\u540e\u4e00\u4e2a\u5355\u5143\u5f39\u51fa\uff08\u51fa\u6808\uff09<\/p>\n<p>\u4fee\u6539\u6570\u7ec4\u4e2d\u67d0\u4e2a\u5143\u7d20<\/p>\n<p>$array1 = array(&#8216;a&#8217;, &#8216;b&#8217;, &#8216;c&#8217;, &#8216;d&#8217;, &#8216;e&#8217;);<\/p>\n<p>$array1[0]=&#8217;aa&#8217;;<\/p>\n<p>print_r($array1);<\/p>\n<h3>\u5e38\u7528\u7684\u6570\u7ec4\u51fd\u6570<\/h3>\n<p>is_array \u5224\u65ad\u662f\u5426\u4e3a\u6570\u7ec4<\/p>\n<p>count \u6570\u7ec4\u7684\u5143\u7d20\u6570\u76ee<\/p>\n<p>array_search \u2014 \u5728\u6570\u7ec4\u4e2d\u641c\u7d22\u7ed9\u5b9a\u7684\u503c\uff0c\u5982\u679c\u6210\u529f\u5219\u8fd4\u56de\u76f8\u5e94\u7684\u952e\u540d<\/p>\n<p>array_key_exists()\u5728\u7ed9\u5b9a\u7684 key \u5b58\u5728\u4e8e\u6570\u7ec4\u4e2d\u65f6\u8fd4\u56de TRUE<\/p>\n<p>array_unshift() \u5c06\u4f20\u5165\u7684\u5355\u5143\u63d2\u5165\u5230 array \u6570\u7ec4\u7684\u5f00\u5934\u3002\u6ce8\u610f\u5355\u5143\u662f\u4f5c\u4e3a\u6574\u4f53\u88ab<\/p>\n<p>\u63d2\u5165\u7684\uff0c\u56e0\u6b64\u4f20\u5165\u5355\u5143\u5c06\u4fdd\u6301\u540c\u6837\u7684\u987a\u5e8f\u3002\u6240\u6709\u7684\u6570\u503c\u952e\u540d\u5c06\u4fee\u6539\u4e3a\u4ece\u96f6\u5f00\u59cb\u91cd<\/p>\n<p>\u65b0\u8ba1\u6570\uff0c\u6240\u6709\u7684\u6587\u5b57\u952e\u540d\u4fdd\u6301\u4e0d\u53d8<\/p>\n<p>array_shift() \u5c06 array \u7684\u7b2c\u4e00\u4e2a\u5355\u5143\u79fb\u51fa\u5e76\u4f5c\u4e3a\u7ed3\u679c\u8fd4\u56de\uff0c\u5c06 array \u7684\u957f\u5ea6\u51cf\u4e00<\/p>\n<p>\u5e76\u5c06\u6240\u6709\u5176\u5b83\u5355\u5143\u5411\u524d\u79fb\u52a8\u4e00\u4f4d\u3002\u6240\u6709\u7684\u6570\u5b57\u952e\u540d\u5c06\u6539\u4e3a\u4ece\u96f6\u5f00\u59cb\u8ba1\u6570\uff0c\u6587\u5b57\u952e<\/p>\n<p>\u540d\u5c06\u4e0d\u53d8\u3002<\/p>\n<p>array_unique() \u63a5\u53d7 array \u4f5c\u4e3a\u8f93\u5165\u5e76\u8fd4\u56de\u6ca1\u6709\u91cd\u590d\u503c\u7684\u65b0\u6570\u7ec4\u3002\u6ce8\u610f\u952e\u540d\u4fdd\u7559<\/p>\n<p>\u4e0d\u53d8\u3002 array_unique() \u5148\u5c06\u503c\u4f5c\u4e3a\u5b57\u7b26\u4e32\u6392\u5e8f\uff0c\u7136\u540e\u5bf9\u6bcf\u4e2a\u503c\u53ea\u4fdd\u7559\u7b2c\u4e00\u4e2a\u9047<\/p>\n<p>\u5230\u7684\u952e\u540d\uff0c\u63a5\u7740\u5ffd\u7565\u6240\u6709\u540e\u9762\u7684\u952e\u540d\u3002\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u5728\u672a\u6392\u5e8f\u7684 array \u4e2d\u540c\u4e00\u4e2a<\/p>\n<p>\u503c\u7684\u7b2c\u4e00\u4e2a\u51fa\u73b0\u7684\u952e\u540d\u4f1a\u88ab\u4fdd\u7559\u3002<\/p>\n<p>in_array \u2014 \u68c0\u67e5\u6570\u7ec4\u4e2d\u662f\u5426\u5b58\u5728\u67d0\u4e2a\u503c \u5982\u679c\u627e\u5230\u6307\u5b9a\u7684\u503c\u5219\u8fd4\u56de TRUE\uff0c\u5426<\/p>\n<p>\u5219\u8fd4\u56de FALSE \u3002in_array()\u662f\u533a\u5206\u5927\u5c0f\u5199\u7684\u3002<\/p>\n<h1>PHP\u51fd\u6570<\/h1>\n<p>PHP \u7684\u771f\u6b63\u529b\u91cf\u6765\u81ea\u5b83\u7684\u51fd\u6570\uff1a\u5b83\u62e5\u6709\u8d85\u8fc7 1000 \u4e2a\u5185\u5efa\u7684\u51fd\u6570\u3002<\/p>\n<p>PHP \u7528\u6237\u5b9a\u4e49\u51fd\u6570<\/p>\n<p>\u9664\u4e86\u5185\u5efa\u7684 PHP \u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u6211\u4eec\u81ea\u5df1\u7684\u51fd\u6570\u3002<\/p>\n<p>\u51fd\u6570\u662f\u53ef\u4ee5\u5728\u7a0b\u5e8f\u4e2d\u91cd\u590d\u4f7f\u7528\u7684\u8bed\u53e5\u5757\u3002<\/p>\n<p>\u9875\u9762\u52a0\u8f7d\u65f6\u51fd\u6570\u4e0d\u4f1a\u7acb\u5373\u6267\u884c\u3002<\/p>\n<p>\u51fd\u6570\u53ea\u6709\u5728\u88ab\u8c03\u7528\u65f6\u624d\u4f1a\u6267\u884c\u3002<\/p>\n<p>\u5728 PHP \u521b\u5efa\u7528\u6237\u5b9a\u4e49\u51fd\u6570<\/p>\n<p>\u7528\u6237\u5b9a\u4e49\u7684\u51fd\u6570\u58f0\u660e\u4ee5\u5355\u8bcd &quot;function&quot; \u5f00\u5934\uff1a<\/p>\n<p>\u8bed\u6cd5<\/p>\n<p>function functionName() {<\/p>\n<p>\u88ab\u6267\u884c\u7684\u4ee3\u7801;<\/p>\n<p>}<\/p>\n<p>\u6ce8\u91ca\uff1a\u51fd\u6570\u540d\u80fd\u591f\u4ee5\u5b57\u6bcd\u6216\u4e0b\u5212\u7ebf\u5f00\u5934\uff08\u800c\u975e\u6570\u5b57\uff09\u3002<\/p>\n<p>\u6ce8\u91ca\uff1a\u51fd\u6570\u540d\u5bf9\u5927\u5c0f\u5199\u4e0d\u654f\u611f\u3002<\/p>\n<p>\u63d0\u793a\uff1a\u51fd\u6570\u540d\u5e94\u8be5\u80fd\u591f\u53cd\u6620\u51fd\u6570\u6240\u6267\u884c\u7684\u4efb\u52a1\u3002<\/p>\n<p>\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u540d\u4e3a &quot;writeMsg()&quot; \u7684\u51fd\u6570\u3002\u6253\u5f00\u7684\u82b1\u62ec\u53f7\uff08{\uff09\u6307\u793a<\/p>\n<p>\u51fd\u6570\u4ee3\u7801\u7684\u5f00\u59cb\uff0c\u800c\u5173\u95ed\u7684\u82b1\u62ec\u53f7\uff08}\uff09\u6307\u793a\u51fd\u6570\u7684\u7ed3\u675f\u3002\u6b64\u51fd\u6570\u8f93\u51fa &quot;Hello<\/p>\n<p>world!&quot;\u3002\u5982\u9700\u8c03\u7528\u8be5\u51fd\u6570\uff0c\u53ea\u8981\u4f7f\u7528\u51fd\u6570\u540d\u5373\u53ef\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nfunction sayHi() {\necho \"Hello world!\";\n}\nsayhi(); \/\/ \u8c03\u7528\u51fd\u6570\n?&gt;<\/code><\/pre>\n<h2>PHP \u51fd\u6570\u53c2\u6570<\/h2>\n<p>\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u5411\u51fd\u6570\u4f20\u9012\u4fe1\u606f\u3002\u53c2\u6570\u7c7b\u4f3c\u53d8\u91cf\u3002<\/p>\n<p>\u53c2\u6570\u88ab\u5b9a\u4e49\u5728\u51fd\u6570\u540d\u4e4b\u540e\uff0c\u62ec\u53f7\u5185\u90e8\u3002\u60a8\u53ef\u4ee5\u6dfb\u52a0\u4efb\u610f\u591a\u53c2\u6570\uff0c\u53ea\u8981\u7528\u9017\u53f7\u9694\u5f00<\/p>\n<p>\u5373\u53ef\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\u7684\u51fd\u6570\u6709\u4e00\u4e2a\u53c2\u6570\uff08$fname\uff09\u3002\u5f53\u8c03\u7528 familyName() \u51fd\u6570\u65f6\uff0c\u6211<\/p>\n<p>\u4eec\u540c\u65f6\u8981\u4f20\u9012\u4e00\u4e2a\u540d\u5b57\uff08\u4f8b\u5982 Bill\uff09\uff0c\u8fd9\u6837\u4f1a\u8f93\u51fa\u4e0d\u540c\u7684\u540d\u5b57\uff0c\u4f46\u662f\u59d3\u6c0f\u76f8\u540c\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nfunction familyName($fname) {\necho \"$fname Zhang.&lt;br&gt;\";\n}\nfamilyName(\"Li\");\nfamilyName(\"Hong\");\nfamilyName(\"Tao\");\nfamilyName(\"Xiao Mei\");\nfamilyName(\"Jian\");\n?&gt;<\/code><\/pre>\n<p>PHP \u9ed8\u8ba4\u53c2\u6570\u503c<\/p>\n<p>\u4e0b\u9762\u7684\u4f8b\u5b50\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u9ed8\u8ba4\u53c2\u6570\u3002\u5982\u679c\u6211\u4eec\u8c03\u7528\u6ca1\u6709\u53c2\u6570\u7684 setHeight() \u51fd<\/p>\n<p>\u6570\uff0c\u5b83\u7684\u53c2\u6570\u4f1a\u53d6\u9ed8\u8ba4\u503c\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nfunction setHeight($minheight=50) {\necho \"The height is : $minheight &lt;br&gt;\";\n}\nsetHeight(350);\nsetHeight(); \/\/ \u5c06\u4f7f\u7528\u9ed8\u8ba4\u503c 50\nsetHeight(135);\nsetHeight(80);\n?&gt;<\/code><\/pre>\n<p>PHP \u51fd\u6570 &#8211; \u8fd4\u56de\u503c<\/p>\n<p>\u5982\u9700\u4f7f\u51fd\u6570\u8fd4\u56de\u503c\uff0c\u8bf7\u4f7f\u7528 return \u8bed\u53e5\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nfunction sum($x,$y) {\n$z=$x+$y;\nreturn $z;\n}\necho \"5 + 10 = \" . sum(5,10) . \"&lt;br&gt;\";\necho \"7 + 13 = \" . sum(7,13) . \"&lt;br&gt;\";\necho \"2 + 4 = \" . sum(2,4);\n?&gt;<\/code><\/pre>\n<h2>\u533f\u540d\u51fd\u6570<\/h2>\n<p>\u533f\u540d\u51fd\u6570\u5c31\u662f\u6ca1\u6709\u540d\u5b57\u7684\u51fd\u6570\u3002<\/p>\n<p>\u5c06\u4e00\u4e2a\u533f\u540d\u51fd\u6570&quot;\u8d4b\u503c&quot;\u7ed9\u4e00\u4e2a\u53d8\u91cf\u2014\u2014\u6b64\u65f6\u8be5\u53d8\u91cf\u5c31\u4ee3\u8868\u8be5\u533f\u540d\u51fd\u6570\u4e86\uff01<\/p>\n<p>$callfunction=function($name){<\/p>\n<p>return $name;<\/p>\n<p>};<\/p>\n<p>echo $callfunction(&#8216;moonsec&#8217;);<\/p>\n<h2>\u56de\u8c03\u51fd\u6570<\/h2>\n<p>\u56de\u8c03\u51fd\u6570\u662f\u6307\u8c03\u7528\u51fd\u6570\u7684\u65f6\u5019\u5c06\u53e6\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u5230\u8c03\u7528\u7684\u51fd\u6570\u4e2d\uff0c\u800c\u4e0d<\/p>\n<p>\u662f\u4f20\u9012\u4e00\u4e2a\u666e\u901a\u7684\u53d8\u91cf\u4f5c\u4e3a\u53c2\u6570<\/p>\n<p>\u4f7f\u7528\u56de\u8c03\u51fd\u6570\u662f\u4e3a\u4e86\u53ef\u4ee5\u5c06\u4e00\u6bb5\u81ea\u5df1\u5b9a\u4e49\u7684\u529f\u80fd\u4f20\u5230\u51fd\u6570\u5185\u90e8\u4f7f\u7528<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nfunction Speak($a,$b){\necho \"He can speak \".$a;\necho \"&lt;br&gt;\";\necho \"She can speak \".$b;\n}\nfunction Speak_Test(){\nreturn call_user_func_array('Speak',array('Chinese','English'));\n}\nSpeak_Test()\n?&gt;<\/code><\/pre>\n<h1>PHP\u53d8\u91cf\u4f5c\u7528\u57df<\/h1>\n<p>\u5728 PHP \u4e2d\uff0c\u53ef\u4ee5\u5728\u811a\u672c\u7684\u4efb\u610f\u4f4d\u7f6e\u5bf9\u53d8\u91cf\u8fdb\u884c\u58f0\u660e\u3002<\/p>\n<p>\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u6307\u7684\u662f\u53d8\u91cf\u80fd\u591f\u88ab\u5f15\u7528\/\u4f7f\u7528\u7684\u90a3\u90e8\u5206\u811a\u672c\u3002<\/p>\n<p>PHP \u6709\u4e09\u79cd\u4e0d\u540c\u7684\u53d8\u91cf\u4f5c\u7528\u57df\uff1a<\/p>\n<p>local\uff08\u5c40\u90e8\uff09<\/p>\n<p>global\uff08\u5168\u5c40\uff09<\/p>\n<p>static\uff08\u9759\u6001\uff09<\/p>\n<p>Local \u548c Global \u4f5c\u7528\u57df<\/p>\n<p>\u51fd\u6570\u4e4b\u5916\u58f0\u660e\u7684\u53d8\u91cf\u62e5\u6709 Global \u4f5c\u7528\u57df\uff0c\u53ea\u80fd\u5728\u51fd\u6570\u4ee5\u5916\u8fdb\u884c\u8bbf\u95ee\u3002<\/p>\n<p>\u51fd\u6570\u5185\u90e8\u58f0\u660e\u7684\u53d8\u91cf\u62e5\u6709 LOCAL \u4f5c\u7528\u57df\uff0c\u53ea\u80fd\u5728\u51fd\u6570\u5185\u90e8\u8fdb\u884c\u8bbf\u95ee\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u4f8b\u5b50\u6d4b\u8bd5\u4e86\u5e26\u6709\u5c40\u90e8\u548c\u5168\u5c40\u4f5c\u7528\u57df\u7684\u53d8\u91cf\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$x=5; \/\/ \u5168\u5c40\u4f5c\u7528\u57df\nfunction myTest() {\n$y=10; \/\/ \u5c40\u90e8\u4f5c\u7528\u57df\necho \"&lt;p&gt;\u6d4b\u8bd5\u51fd\u6570\u5185\u90e8\u7684\u53d8\u91cf\uff1a&lt;\/p&gt;\";\necho \"\u53d8\u91cf x \u662f\uff1a$x\";\necho \"&lt;br&gt;\";\necho \"\u53d8\u91cf y \u662f\uff1a$y\";\n}\nmyTest();\necho \"&lt;p&gt;\u6d4b\u8bd5\u51fd\u6570\u4e4b\u5916\u7684\u53d8\u91cf\uff1a&lt;\/p&gt;\";\necho \"\u53d8\u91cf x \u662f\uff1a$x\";\necho \"&lt;br&gt;\";\necho \"\u53d8\u91cf y \u662f\uff1a$y\";\n?&gt;<\/code><\/pre>\n<p>\u5728\u4e0a\u4f8b\u4e2d\uff0c\u6709\u4e24\u4e2a\u53d8\u91cf $x \u548c $y\uff0c\u4ee5\u53ca\u4e00\u4e2a\u51fd\u6570 myTest()\u3002$x \u662f\u5168\u5c40\u53d8\u91cf\uff0c<\/p>\n<p>\u56e0\u4e3a\u5b83\u662f\u5728\u51fd\u6570\u4e4b\u5916\u58f0\u660e\u7684\uff0c\u800c $y \u662f\u5c40\u90e8\u53d8\u91cf\uff0c\u56e0\u4e3a\u5b83\u662f\u5728\u51fd\u6570\u5185\u58f0\u660e\u7684\u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u5728 myTest() \u51fd\u6570\u5185\u90e8\u8f93\u51fa\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\uff0c$y \u4f1a\u8f93\u51fa\u5728\u672c\u5730\u58f0\u660e\u7684\u503c\uff0c<\/p>\n<p>\u4f46\u662f\u65e0\u6cd5 $x \u7684\u503c\uff0c\u56e0\u4e3a\u5b83\u5728\u51fd\u6570\u4e4b\u5916\u521b\u5efa\u3002<\/p>\n<p>\u7136\u540e\uff0c\u5982\u679c\u5728 myTest() \u51fd\u6570\u4e4b\u5916\u8f93\u51fa\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\uff0c\u90a3\u4e48\u4f1a\u8f93\u51fa $x \u7684\u503c\uff0c\u4f46<\/p>\n<p>\u662f\u4e0d\u4f1a\u8f93\u51fa $y \u7684\u503c\uff0c\u56e0\u4e3a\u5b83\u662f\u5c40\u90e8\u53d8\u91cf\uff0c\u5e76\u4e14\u5728 myTest() \u5185\u90e8\u521b\u5efa\u3002<\/p>\n<p>\u6ce8\u91ca\uff1a\u60a8\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u51fd\u6570\u4e2d\u521b\u5efa\u540d\u79f0\u76f8\u540c\u7684\u5c40\u90e8\u53d8\u91cf\uff0c\u56e0\u4e3a\u5c40\u90e8\u53d8\u91cf\u53ea\u80fd\u88ab\u5728<\/p>\n<p>\u5176\u4e2d\u521b\u5efa\u5b83\u7684\u51fd\u6570\u8bc6\u522b\u3002<\/p>\n<p>PHP global \u5173\u952e\u8bcd<\/p>\n<p>global \u5173\u952e\u8bcd\u7528\u4e8e\u5728\u51fd\u6570\u5185\u8bbf\u95ee\u5168\u5c40\u53d8\u91cf\u3002<\/p>\n<p>\u8981\u505a\u5230\u8fd9\u4e00\u70b9\uff0c\u8bf7\u5728\uff08\u51fd\u6570\u5185\u90e8\uff09\u53d8\u91cf\u524d\u9762\u4f7f\u7528 global \u5173\u952e\u8bcd\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$x=5;\n$y=10;\nfunction myTest() {\nglobal $x,$y;\n$y=$x+$y;\n}\nmyTest();\necho $y; \/\/ \u8f93\u51fa 15\n?&gt;<\/code><\/pre>\n<p>PHP \u540c\u65f6\u5728\u540d\u4e3a $GLOBALS[index] \u7684\u6570\u7ec4\u4e2d\u5b58\u50a8\u4e86\u6240\u6709\u7684\u5168\u5c40\u53d8\u91cf\u3002\u4e0b\u6807\u5b58<\/p>\n<p>\u6709\u53d8\u91cf\u540d\u3002\u8fd9\u4e2a\u6570\u7ec4\u5728\u51fd\u6570\u5185\u4e5f\u53ef\u4ee5\u8bbf\u95ee\uff0c\u5e76\u80fd\u591f\u7528\u4e8e\u76f4\u63a5\u66f4\u65b0\u5168\u5c40\u53d8\u91cf\u3002<\/p>\n<p>\u4e0a\u9762\u7684\u4f8b\u5b50\u53ef\u4ee5\u8fd9\u6837\u91cd\u5199\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$x=5;\n$y=10;\nfunction myTest() {\n$GLOBALS['y']=$GLOBALS['x']+$GLOBALS['y'];\n}\nmyTest();\necho $y; \/\/ \u8f93\u51fa 15\n?&gt;<\/code><\/pre>\n<h3>PHP static \u5173\u952e\u8bcd<\/h3>\n<p>\u901a\u5e38\uff0c\u5f53\u51fd\u6570\u5b8c\u6210\/\u6267\u884c\u540e\uff0c\u4f1a\u5220\u9664\u6240\u6709\u53d8\u91cf\u3002\u4e0d\u8fc7\uff0c\u6709\u65f6\u6211\u9700\u8981\u4e0d\u5220\u9664\u67d0\u4e2a\u5c40<\/p>\n<p>\u90e8\u53d8\u91cf\u3002\u5b9e\u73b0\u8fd9\u4e00\u70b9\u9700\u8981\u66f4\u8fdb\u4e00\u6b65\u7684\u5de5\u4f5c\u3002<\/p>\n<p>\u8981\u5b8c\u6210\u8fd9\u4e00\u70b9\uff0c\u8bf7\u5728\u60a8\u9996\u6b21\u58f0\u660e\u53d8\u91cf\u65f6\u4f7f\u7528 static \u5173\u952e\u8bcd\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nfunction myTest() {\nstatic $x=0;\necho $x;\n$x++;\n}\nmyTest();\nmyTest();\nmyTest();\n?&gt;<\/code><\/pre>\n<p>\u7136\u540e\uff0c\u6bcf\u5f53\u51fd\u6570\u88ab\u8c03\u7528\u65f6\uff0c\u8fd9\u4e2a\u53d8\u91cf\u6240\u5b58\u50a8\u7684\u4fe1\u606f\u90fd\u662f\u51fd\u6570\u6700\u540e\u4e00\u6b21\u88ab\u8c03\u7528\u65f6\u6240<\/p>\n<p>\u5305\u542b\u7684\u4fe1\u606f\u3002\/\/\/<\/p>\n<p>\u6ce8\u91ca\uff1a\u8be5\u53d8\u91cf\u4ecd\u7136\u662f\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u3002<\/p>\n<h1>\u7c7b\u4e0e\u5bf9\u8c61<\/h1>\n<p>PHP \u9762\u5411\u5bf9\u8c61<\/p>\n<p>\u5728\u9762\u5411\u5bf9\u8c61\u7684\u7a0b\u5e8f\u8bbe\u8ba1\uff08\u82f1\u8bed\uff1aObject-oriented programming\uff0c\u7f29\u5199\uff1aOOP\uff09\u4e2d\uff0c<\/p>\n<p>\u5bf9\u8c61\u662f\u4e00\u4e2a\u7531\u4fe1\u606f\u53ca\u5bf9\u4fe1\u606f\u8fdb\u884c\u5904\u7406\u7684\u63cf\u8ff0\u6240\u7ec4\u6210\u7684\u6574\u4f53\uff0c\u662f\u5bf9\u73b0\u5b9e\u4e16\u754c\u7684\u62bd\u8c61\u3002<\/p>\n<p>\u5728\u73b0\u5b9e\u4e16\u754c\u91cc\u6211\u4eec\u6240\u9762\u5bf9\u7684\u4e8b\u60c5\u90fd\u662f\u5bf9\u8c61\uff0c\u5982\u8ba1\u7b97\u673a\u3001\u7535\u89c6\u673a\u3001\u81ea\u884c\u8f66\u7b49\u3002<\/p>\n<p>\u5bf9\u8c61\u7684\u4e3b\u8981\u4e09\u4e2a\u7279\u6027\uff1a<\/p>\n<p>\u5bf9\u8c61\u7684\u884c\u4e3a\uff1a\u53ef\u4ee5\u5bf9\u5bf9\u8c61\u65bd\u52a0\u90a3\u4e9b\u64cd\u4f5c\uff0c\u5f00\u706f\uff0c\u5173\u706f\u5c31\u662f\u884c\u4e3a\u3002<\/p>\n<p>\u5bf9\u8c61\u7684\u5f62\u6001\uff1a\u5f53\u65bd\u52a0\u90a3\u4e9b\u65b9\u6cd5\u662f\u5bf9\u8c61\u5982\u4f55\u54cd\u5e94\uff0c\u989c\u8272\uff0c\u5c3a\u5bf8\uff0c\u5916\u578b\u3002<\/p>\n<p>\u5bf9\u8c61\u7684\u8868\u793a\uff1a\u5bf9\u8c61\u7684\u8868\u793a\u5c31\u76f8\u5f53\u4e8e\u8eab\u4efd\u8bc1\uff0c\u5177\u4f53\u533a\u5206\u5728\u76f8\u540c\u7684\u884c\u4e3a\u4e0e\u72b6\u6001\u4e0b<\/p>\n<p>\u6709\u4ec0\u4e48\u4e0d\u540c\u3002<\/p>\n<p>\u6bd4\u5982 Animal(\u52a8\u7269) \u662f\u4e00\u4e2a\u62bd\u8c61\u7c7b\uff0c\u6211\u4eec\u53ef\u4ee5\u5177\u4f53\u5230\u4e00\u53ea\u72d7\u8ddf\u4e00\u53ea\u7f8a\uff0c\u800c\u72d7\u8ddf\u7f8a<\/p>\n<p>\u5c31\u662f\u5177\u4f53\u7684\u5bf9\u8c61\uff0c\u4ed6\u4eec\u6709\u989c\u8272\u5c5e\u6027\uff0c\u53ef\u4ee5\u5199\uff0c\u53ef\u4ee5\u8dd1\u7b49\u884c\u4e3a\u72b6\u6001\u3002<\/p>\n<h2>\u9762\u5411\u5bf9\u8c61\u5185\u5bb9<\/h2>\n<p><strong>\u7c7b <\/strong>\u2212 \u5b9a\u4e49\u4e86\u4e00\u4ef6\u4e8b\u7269\u7684\u62bd\u8c61\u7279\u70b9\u3002\u7c7b\u7684\u5b9a\u4e49\u5305\u542b\u4e86\u6570\u636e\u7684\u5f62\u5f0f\u4ee5\u53ca\u5bf9\u6570\u636e\u7684\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5bf9\u8c61<\/strong> \u2212 \u662f\u7c7b\u7684\u5b9e\u4f8b\u3002<\/p>\n<p><strong>\u6210\u5458\u53d8\u91cf<\/strong> \u2212 \u5b9a\u4e49\u5728\u7c7b\u5185\u90e8\u7684\u53d8\u91cf\u3002\u8be5\u53d8\u91cf\u7684\u503c\u5bf9\u5916\u662f\u4e0d\u53ef\u89c1\u7684\uff0c\u4f46\u662f\u53ef\u4ee5\u901a\u8fc7\u6210\u5458\u51fd\u6570\u8bbf\u95ee\uff0c\u5728\u7c7b\u88ab\u5b9e\u4f8b\u5316\u4e3a\u5bf9\u8c61\u540e\uff0c\u8be5\u53d8\u91cf\u5373\u53ef\u79f0\u4e3a\u5bf9\u8c61\u7684\u5c5e\u6027\u3002<\/p>\n<p><strong>\u6210\u5458\u51fd\u6570<\/strong> \u2212 \u5b9a\u4e49\u5728\u7c7b\u7684\u5185\u90e8\uff0c\u53ef\u7528\u4e8e\u8bbf\u95ee\u5bf9\u8c61\u7684\u6570\u636e\u3002<\/p>\n<p><strong>\u7ee7\u627f<\/strong> \u2212 \u7ee7\u627f\u6027\u662f\u5b50\u7c7b\u81ea\u52a8\u5171\u4eab\u7236\u7c7b\u6570\u636e\u7ed3\u6784\u548c\u65b9\u6cd5\u7684\u673a\u5236\uff0c\u8fd9\u662f\u7c7b\u4e4b\u95f4\u7684\u4e00\u79cd\u5173\u7cfb\u3002\u5728\u5b9a\u4e49\u548c\u5b9e\u73b0\u4e00\u4e2a\u7c7b\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u5728\u4e00\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u7c7b\u7684\u57fa\u7840\u4e4b\u4e0a\u6765\u8fdb\u884c\uff0c\u628a\u8fd9\u4e2a\u5df2\u7ecf\u5b58\u5728\u7684\u7c7b\u6240\u5b9a\u4e49\u7684\u5185\u5bb9\u4f5c\u4e3a\u81ea\u5df1\u7684\u5185\u5bb9\uff0c\u5e76\u52a0\u5165\u82e5\u5e72\u65b0\u7684\u5185\u5bb9\u3002<\/p>\n<p><strong>\u7236\u7c7b<\/strong> \u2212 \u4e00\u4e2a\u7c7b\u88ab\u5176\u4ed6\u7c7b\u7ee7\u627f\uff0c\u53ef\u5c06\u8be5\u7c7b\u79f0\u4e3a\u7236\u7c7b\uff0c\u6216\u57fa\u7c7b\uff0c\u6216\u8d85\u7c7b\u3002<\/p>\n<p><strong>\u5b50\u7c7b<\/strong> \u2212 \u4e00\u4e2a\u7c7b\u7ee7\u627f\u5176\u4ed6\u7c7b\u79f0\u4e3a\u5b50\u7c7b\uff0c\u4e5f\u53ef\u79f0\u4e3a\u6d3e\u751f\u7c7b\u3002<\/p>\n<p><strong>\u591a\u6001<\/strong> \u2212 \u591a\u6001\u6027\u662f\u6307\u76f8\u540c\u7684\u64cd\u4f5c\u6216\u51fd\u6570\u3001\u8fc7\u7a0b\u53ef\u4f5c\u7528\u4e8e\u591a\u79cd\u7c7b\u578b\u7684\u5bf9\u8c61\u4e0a\u5e76\u83b7\u5f97\u4e0d\u540c\u7684\u7ed3\u679c\u3002\u4e0d\u540c\u7684\u5bf9\u8c61\uff0c\u6536\u5230\u540c\u4e00\u6d88\u606f\u53ef\u4ee5\u4ea7\u751f\u4e0d\u540c\u7684\u7ed3\u679c\uff0c\u8fd9\u79cd\u73b0\u8c61\u79f0\u4e3a\u591a\u6001\u6027\u3002<\/p>\n<p><strong>\u91cd\u8f7d<\/strong> \u2212 \u7b80\u5355\u8bf4\uff0c\u5c31\u662f\u51fd\u6570\u6216\u8005\u65b9\u6cd5\u6709\u540c\u6837\u7684\u540d\u79f0\uff0c\u4f46\u662f\u53c2\u6570\u5217\u8868\u4e0d\u76f8\u540c\u7684\u60c5\u5f62\uff0c\u8fd9\u6837\u7684\u540c\u540d\u4e0d\u540c\u53c2\u6570\u7684\u51fd\u6570\u6216\u8005\u65b9\u6cd5\u4e4b\u95f4\uff0c\u4e92\u76f8\u79f0\u4e4b\u4e3a\u91cd\u8f7d\u51fd\u6570\u6216\u8005\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u62bd\u8c61\u6027<\/strong> \u2212 \u62bd\u8c61\u6027\u662f\u6307\u5c06\u5177\u6709\u4e00\u81f4\u7684\u6570\u636e\u7ed3\u6784\uff08\u5c5e\u6027\uff09\u548c\u884c\u4e3a\uff08\u64cd\u4f5c\uff09\u7684\u5bf9\u8c61\u62bd\u8c61\u6210\u7c7b\u3002\u4e00\u4e2a\u7c7b\u5c31\u662f\u8fd9\u6837\u4e00\u79cd\u62bd\u8c61\uff0c\u5b83\u53cd\u6620\u4e86\u4e0e\u5e94\u7528\u6709\u5173\u7684\u91cd\u8981\u6027\u8d28\uff0c\u800c\u5ffd\u7565\u5176\u4ed6\u4e00\u4e9b\u65e0\u5173\u5185\u5bb9\u3002\u4efb\u4f55\u7c7b\u7684\u5212\u5206\u90fd\u662f\u4e3b\u89c2\u7684\uff0c\u4f46\u5fc5\u987b\u4e0e\u5177\u4f53\u7684\u5e94\u7528\u6709\u5173\u3002<\/p>\n<p><strong>\u5c01\u88c5<\/strong> \u2212 \u5c01\u88c5\u662f\u6307\u5c06\u73b0\u5b9e\u4e16\u754c\u4e2d\u5b58\u5728\u7684\u67d0\u4e2a\u5ba2\u4f53\u7684\u5c5e\u6027\u4e0e\u884c\u4e3a\u7ed1\u5b9a\u5728\u4e00\u8d77\uff0c\u5e76\u653e\u7f6e\u5728\u4e00\u4e2a\u903b\u8f91\u5355\u5143\u5185\u3002<\/p>\n<p><strong>\u6784\u9020\u51fd\u6570<\/strong> \u2212 \u4e3b\u8981\u7528\u6765\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u521d\u59cb\u5316\u5bf9\u8c61\uff0c \u5373\u4e3a\u5bf9\u8c61\u6210\u5458\u53d8\u91cf\u8d4b\u521d\u59cb\u503c\uff0c\u603b\u4e0e new \u8fd0\u7b97\u7b26\u4e00\u8d77\u4f7f\u7528\u5728\u521b\u5efa\u5bf9\u8c61\u7684\u8bed\u53e5\u4e2d\u3002<\/p>\n<p><strong>\u6790\u6784\u51fd\u6570<\/strong> \u2212 \u6790\u6784\u51fd\u6570(destructor) \u4e0e\u6784\u9020\u51fd\u6570\u76f8\u53cd\uff0c\u5f53\u5bf9\u8c61\u7ed3\u675f\u5176\u751f\u547d\u5468\u671f\u65f6\uff08\u4f8b\u5982\u5bf9\u8c61\u6240\u5728\u7684\u51fd\u6570\u5df2\u8c03\u7528\u5b8c\u6bd5\uff09\uff0c\u7cfb\u7edf\u81ea\u52a8\u6267\u884c\u6790\u6784\u51fd\u6570\u3002\u6790\u6784\u51fd\u6570\u5f80\u5f80\u7528\u6765\u505a&quot;\u6e05\u7406\u5584\u540e&quot; \u7684\u5de5\u4f5c\uff08\u4f8b\u5982\u5728\u5efa\u7acb\u5bf9\u8c61\u65f6\u7528 new \u5f00\u8f9f\u4e86\u4e00\u7247\u5185\u5b58\u7a7a\u95f4\uff0c\u5e94\u5728\u9000\u51fa\u524d\u5728\u6790\u6784\u51fd\u6570\u4e2d\u7528 delete \u91ca\u653e\uff09\u3002<\/p>\n<p>\u4e0b\u56fe\u4e2d\u6211\u4eec\u901a\u8fc7 Car \u7c7b \u521b\u5efa\u4e86\u4e09\u4e2a\u5bf9\u8c61\uff1aMercedes, Bmw, \u548c Audi\u3002<\/p>\n<p>$mercedes = new Car ();<\/p>\n<p>$bmw = new Car ();<\/p>\n<p>$audi = new Car ();<\/p>\n<p><img loading="lazy" decoding="async" decoding=\"async\"  src=\"https:\/\/www.youvii.site\/wp-content\/themes\/lolimeow-lolimeowV13.13\/assets\/images\/loading.gif\" data-src=\"https:\/\/cdn.picui.cn\/vip\/2025\/10\/24\/68faeac70d76a.png\" class=\"lazy\" loading=\"lazy\" alt=\"1745378344019-f740992a-f9be-480b-9413-2945113b5cab.png\" \/><\/p>\n<h2>PHP \u7c7b\u5b9a\u4e49<\/h2>\n<p>PHP \u5b9a\u4e49\u7c7b\u901a\u5e38\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nclass phpClass {\nvar $var1;\nvar $var2 = \"constant string\";\nfunction myfunc ($arg1, $arg2) {\n[..]\n}\n[..]\n}\n?&gt;<\/code><\/pre>\n<p>\u89e3\u6790\u5982\u4e0b\uff1a<\/p>\n<p>\u7c7b\u4f7f\u7528 class \u5173\u952e\u5b57\u540e\u52a0\u4e0a\u7c7b\u540d\u5b9a\u4e49\u3002<\/p>\n<p>\u7c7b\u540d\u540e\u7684\u4e00\u5bf9\u5927\u62ec\u53f7({})\u5185\u53ef\u4ee5\u5b9a\u4e49\u53d8\u91cf\u548c\u65b9\u6cd5\u3002<\/p>\n<p>\u7c7b\u7684\u53d8\u91cf\u4f7f\u7528 var \u6765\u58f0\u660e, \u53d8\u91cf\u4e5f\u53ef\u4ee5\u521d\u59cb\u5316\u503c\u3002<\/p>\n<p>\u51fd\u6570\u5b9a\u4e49\u7c7b\u4f3c PHP \u51fd\u6570\u7684\u5b9a\u4e49\uff0c\u4f46\u51fd\u6570\u53ea\u80fd\u901a\u8fc7\u8be5\u7c7b\u53ca\u5176\u5b9e\u4f8b\u5316\u7684\u5bf9\u8c61\u8bbf\u95ee\u3002<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nclass Site {\n\/* \u6210\u5458\u53d8\u91cf *\/\nvar $url;\nvar $title;\n\/* \u6210\u5458\u51fd\u6570 *\/\nfunction setUrl($par){\n$this-&gt;url = $par;\n}\nfunction getUrl(){\necho $this-&gt;url . PHP_EOL;\n}\nfunction setTitle($par){\n$this-&gt;title = $par;\n}\nfunction getTitle(){\necho $this-&gt;title . PHP_EOL;\n}\n}\n?&gt;<\/code><\/pre>\n<p>\u53d8\u91cf $this \u4ee3\u8868\u81ea\u8eab\u7684\u5bf9\u8c61\u3002<\/p>\n<p>PHP_EOL \u4e3a\u6362\u884c\u7b26\u3002<\/p>\n<p>PHP \u4e2d\u521b\u5efa\u5bf9\u8c61<\/p>\n<p>\u7c7b\u521b\u5efa\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 new \u8fd0\u7b97\u7b26\u6765\u5b9e\u4f8b\u5316\u8be5\u7c7b\u7684\u5bf9\u8c61\uff1a<\/p>\n<p>$w3cschool = new Site;<\/p>\n<p>$taobao = new Site;<\/p>\n<p>$google = new Site;<\/p>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u6211\u4eec\u521b\u5efa\u4e86\u4e09\u4e2a\u5bf9\u8c61\uff0c\u4e09\u4e2a\u5bf9\u8c61\u5404\u81ea\u90fd\u662f\u72ec\u7acb\u7684\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u6765\u770b\u770b\u5982<\/p>\n<p>\u4f55\u8bbf\u95ee\u6210\u5458\u65b9\u6cd5\u4e0e\u6210\u5458\u53d8\u91cf\u3002<\/p>\n<p>\u8c03\u7528\u6210\u5458\u65b9\u6cd5<\/p>\n<p>\u5728\u5b9e\u4f8b\u5316\u5bf9\u8c61\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8be5\u5bf9\u8c61\u8c03\u7528\u6210\u5458\u65b9\u6cd5\uff0c\u8be5\u5bf9\u8c61\u7684\u6210\u5458\u65b9\u6cd5\u53ea\u80fd\u64cd<\/p>\n<p>\u4f5c\u8be5\u5bf9\u8c61\u7684\u6210\u5458\u53d8\u91cf\uff1a<\/p>\n<p>\/\/ \u8c03\u7528\u6210\u5458\u51fd\u6570\uff0c\u8bbe\u7f6e\u6807\u9898\u548c URL<\/p>\n<p>$w3cschool-&gt;setTitle( &quot;W3Cschool \u6559\u7a0b&quot; );<\/p>\n<p>$taobao-&gt;setTitle( &quot;\u6dd8\u5b9d&quot; );<\/p>\n<p>$google-&gt;setTitle( &quot;Google \u641c\u7d22&quot; );<\/p>\n<p>$w3cschool-&gt;setUrl( &#8216;www.w3cschool.cn&#8217; );<\/p>\n<p>$taobao-&gt;setUrl( &#8216;www.taobao.com&#8217; );<\/p>\n<p>$google-&gt;setUrl( &#8216;www.google.com&#8217; );<\/p>\n<p>\/\/ \u8c03\u7528\u6210\u5458\u51fd\u6570\uff0c\u83b7\u53d6\u6807\u9898\u548c URL<\/p>\n<p>$w3cschool-&gt;getTitle();<\/p>\n<p>$taobao-&gt;getTitle();<\/p>\n<p>$google-&gt;getTitle();<\/p>\n<p>$w3cschool-&gt;getUrl();<\/p>\n<p>$taobao-&gt;getUrl();<\/p>\n<p>$google-&gt;getUrl();<\/p>\n<p>\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nclass Site {\n\/* \u6210\u5458\u53d8\u91cf *\/\nvar $url;\nvar $title;\n\/* \u6210\u5458\u51fd\u6570 *\/\nfunction setUrl($par){\n$this -&gt;url = $par;\n}\nfunction getUrl (){\necho $this-&gt;url . PHP_EOL ;\n}\nfunction setTitle($par){\n$this -&gt;title = $par;\n}\nfunction getTitle (){\necho $this-&gt;title . PHP_EOL ;\n}\n}\n$w3cschool = new Site;\n$taobao = new Site;\n$google = new Site;\n\/\/ \u8c03\u7528\u6210\u5458\u51fd\u6570\uff0c\u8bbe\u7f6e\u6807\u9898\u548c URL\n$w3cschool-&gt;setTitle( \"W3Cschool \u6559\u7a0b\" );\n$taobao -&gt;setTitle( \"\u6dd8\u5b9d\" );\n$google-&gt; setTitle( \"Google \u641c\u7d22\" );\n$w3cschool-&gt; setUrl( 'www.w3cschool.cn' );\n$taobao-&gt;setUrl ( 'www.taobao.com' );\n$google-&gt;setUrl( 'www.google.com' );\n\/\/ \u8c03\u7528\u6210\u5458\u51fd\u6570\uff0c\u83b7\u53d6\u6807\u9898\u548c URL\n$w3cschool-&gt;getTitle ();\n$taobao-&gt;getTitle();\n$google-&gt; getTitle();\n$w3cschool-&gt;getUrl();\n$taobao -&gt;getUrl();\n$google-&gt;getUrl();\n?&gt;<\/code><\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u4ee3\u7801\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p>W3Cschool \u6559\u7a0b<\/p>\n<p>\u6dd8\u5b9d<\/p>\n<p>Google \u641c\u7d22<\/p>\n<p>www.w3cschool.cn<\/p>\n<p>www.taobao.com<\/p>\n<p>www.google.com<\/p>\n<h3>PHP \u6784\u9020\u51fd\u6570<\/h3>\n<p>\u6784\u9020\u51fd\u6570 \uff0c\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u65b9\u6cd5\u3002\u4e3b\u8981\u7528\u6765\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u521d\u59cb\u5316\u5bf9\u8c61\uff0c \u5373\u4e3a\u5bf9\u8c61\u6210\u5458\u53d8\u91cf\u8d4b\u521d\u59cb\u503c\uff0c\u603b\u4e0e new \u8fd0\u7b97\u7b26\u4e00\u8d77\u4f7f\u7528\u5728\u521b\u5efa\u5bf9\u8c61\u7684\u8bed\u53e5\u4e2d\u3002<\/p>\n<p>PHP 5 \u5141\u884c\u5f00\u53d1\u8005\u5728\u4e00\u4e2a\u7c7b\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5\u4f5c\u4e3a\u6784\u9020\u51fd\u6570\uff0c\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>void __construct ([ mixed $args [, $&#8230; ]] )<\/p>\n<p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\u6211\u4eec\u5c31\u53ef\u4ee5\u901a\u8fc7\u6784\u9020\u65b9\u6cd5\u6765\u521d\u59cb\u5316 $url \u548c $title \u53d8\u91cf\uff1a<\/p>\n<p>function __construct( $par1, $par2 ) {<\/p>\n<p>$this-&gt;url = $par1;<\/p>\n<p>$this-&gt;title = $par2;<\/p>\n<p>}<\/p>\n<p>\u73b0\u5728\u6211\u4eec\u5c31\u4e0d\u9700\u8981\u518d\u8c03\u7528 setTitle \u548c setUrl \u65b9\u6cd5\u4e86\uff1a<\/p>\n<p>$youj = new Site(&#8216;www.w3cschool.cn&#8217;, &#8216;W3Cschool \u6559\u7a0b&#8217;);<\/p>\n<p>$taobao = new Site(&#8216;www.taobao.com&#8217;, &#8216;\u6dd8\u5b9d&#8217;);<\/p>\n<p>$google = new Site(&#8216;www.google.com&#8217;, &#8216;Google \u641c\u7d22&#8217;);<\/p>\n<p>\/\/ \u8c03\u7528\u6210\u5458\u51fd\u6570\uff0c\u83b7\u53d6\u6807\u9898\u548c URL<\/p>\n<p>$youj-&gt;getTitle();<\/p>\n<p>$taobao-&gt;getTitle();<\/p>\n<p>$google-&gt;getTitle();<\/p>\n<p>$youj-&gt;getUrl();<\/p>\n<p>$taobao-&gt;getUrl();<\/p>\n<p>$google-&gt;getUrl();<\/p>\n<h3>\u6790\u6784\u51fd\u6570<\/h3>\n<p>\u6790\u6784\u51fd\u6570(destructor) \u4e0e\u6784\u9020\u51fd\u6570\u76f8\u53cd\uff0c\u5f53\u5bf9\u8c61\u7ed3\u675f\u5176\u751f\u547d\u5468\u671f\u65f6\uff08\u4f8b\u5982\u5bf9\u8c61\u6240\u5728\u7684\u51fd\u6570\u5df2\u8c03\u7528\u5b8c\u6bd5\uff09\uff0c\u7cfb\u7edf\u81ea\u52a8\u6267\u884c\u6790\u6784\u51fd\u6570\u3002<\/p>\n<p>PHP 5 \u5f15\u5165\u4e86\u6790\u6784\u51fd\u6570\u7684\u6982\u5ff5\uff0c\u8fd9\u7c7b\u4f3c\u4e8e\u5176\u5b83\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u8a00\uff0c\u5176\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>void __destruct ( void )<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nclass MyDestructableClass {\nfunction __construct() {\nprint \"\u6784\u9020\u51fd\u6570n\";\n$this-&gt;name = \"MyDestructableClass\";\n}\nfunction __destruct() {\nprint \"\u9500\u6bc1 \" . $this-&gt;name . \"n\";\n}\n}\n$obj = new MyDestructableClass();\n?&gt;<\/code><\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u4ee3\u7801\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p>\u6784\u9020\u51fd\u6570<\/p>\n<p>\u9500\u6bc1 MyDestructableClass<\/p>\n<h3>\u7ee7\u627f<\/h3>\n<p>\u7ee7\u627f\u5c31\u662f\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u7684\u7279\u5f81\u548c\u884c\u4e3a\uff0c\u4f7f\u5f97\u5b50\u7c7b\u5bf9\u8c61\uff08\u5b9e\u4f8b\uff09\u5177\u6709\u7236\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u6216\u5b50\u7c7b\u4ece\u7236\u7c7b\u7ee7\u627f\u65b9\u6cd5\uff0c\u4f7f\u5f97\u5b50\u7c7b\u5177\u6709\u7236\u7c7b\u76f8\u540c\u7684\u884c\u4e3a\u3002<\/p>\n<p>\u7236\u7c7b=\u57fa\u7c7b<\/p>\n<p>PHP \u4f7f\u7528\u5173\u952e\u5b57 extends \u6765\u7ee7\u627f\u4e00\u4e2a\u7c7b\uff0cPHP \u4e0d\u652f\u6301\u591a\u7ee7\u627f\uff0c\u683c\u5f0f<\/p>\n<p>class Child extends Parent {<\/p>\n<p>\/\/ \u4ee3\u7801\u90e8\u5206<\/p>\n<p>}<\/p>\n<p>\u5982\u4e0b\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<p>\u5b9e\u4f8b\u4e2d Child_Site \u7c7b\u7ee7\u627f\u4e86 Site \u7c7b\uff0c\u5e76\u6269\u5c55\u4e86\u529f\u80fd\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n\/\/ \u5b50\u7c7b\u6269\u5c55\u7ad9\u70b9\u7c7b\u522b\nclass Child_Site extends Site {\nvar $category;\nfunction setCate($par){\n$this-&gt;category = $par;\n}\nfunction getCate(){\necho $this-&gt;category . PHP_EOL;\n}\n}<\/code><\/pre>\n<h3>\u65b9\u6cd5\u91cd\u5199<\/h3>\n<p>\u5982\u679c\u4ece\u7236\u7c7b\u7ee7\u627f\u7684\u65b9\u6cd5\u4e0d\u80fd\u6ee1\u8db3\u5b50\u7c7b\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u5bf9\u5176\u8fdb\u884c\u6539\u5199\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u53eb\u65b9\u6cd5\u7684\u8986\u76d6\uff08override\uff09\uff0c\u4e5f\u79f0\u4e3a\u65b9\u6cd5\u7684\u91cd\u5199\u3002<\/p>\n<p>\u5b9e\u4f8b\u4e2d\u91cd\u5199\u4e86 getUrl \u4e0e getTitle \u65b9\u6cd5\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">function getUrl() {\necho $this-&gt;url . PHP_EOL;\nreturn $this-&gt;url;\n}\nfunction getTitle(){\necho $this-&gt;title . PHP_EOL;\nreturn $this-&gt;title;\n}<\/code><\/pre>\n<h3>\u8bbf\u95ee\u63a7\u5236<\/h3>\n<p>PHP \u5bf9\u5c5e\u6027\u6216\u65b9\u6cd5\u7684\u8bbf\u95ee\u63a7\u5236\uff0c\u662f\u901a\u8fc7\u5728\u524d\u9762\u6dfb\u52a0\u5173\u952e\u5b57 public\uff08\u516c\u6709\uff09\uff0c<\/p>\n<p>protected\uff08\u53d7\u4fdd\u62a4\uff09\u6216 private\uff08\u79c1\u6709\uff09\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n<p>public\uff08\u516c\u6709\uff09\uff1a\u516c\u6709\u7684\u7c7b\u6210\u5458\u53ef\u4ee5\u5728\u4efb\u4f55\u5730\u65b9\u88ab\u8bbf\u95ee\u3002<\/p>\n<p>protected\uff08\u53d7\u4fdd\u62a4\uff09\uff1a\u53d7\u4fdd\u62a4\u7684\u7c7b\u6210\u5458\u5219\u53ef\u4ee5\u88ab\u5176\u81ea\u8eab\u4ee5\u53ca\u5176\u5b50\u7c7b\u548c\u7236\u7c7b\u8bbf\u95ee\u3002<\/p>\n<p>private\uff08\u79c1\u6709\uff09\uff1a\u79c1\u6709\u7684\u7c7b\u6210\u5458\u5219\u53ea\u80fd\u88ab\u5176\u5b9a\u4e49\u6240\u5728\u7684\u7c7b\u8bbf\u95ee\u3002<\/p>\n<p>\u5c5e\u6027\u7684\u8bbf\u95ee\u63a7\u5236\u7c7b\u5c5e\u6027\u5fc5\u987b\u5b9a\u4e49\u4e3a\u516c\u6709\uff0c\u53d7\u4fdd\u62a4\uff0c\u79c1\u6709\u4e4b\u4e00\u3002\u5982\u679c\u7528 var \u5b9a\u4e49\uff0c\u5219\u88ab\u89c6\u4e3a\u516c\u6709\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n\/**\n* Define MyClass\n*\/\nclass MyClass\n{\npublic $public = 'Public';\nprotected $protected = 'Protected';\nprivate $private = 'Private';\nfunction printHello()\n{\necho $this-&gt;public;\necho $this-&gt;protected;\necho $this-&gt;private;\n}\n}\n$obj = new MyClass();\necho $obj-&gt;public; \/\/ \u8fd9\u884c\u80fd\u88ab\u6b63\u5e38\u6267\u884c\necho $obj-&gt;protected; \/\/ \u8fd9\u884c\u4f1a\u4ea7\u751f\u4e00\u4e2a\u81f4\u547d\u9519\u8bef\necho $obj-&gt;private; \/\/ \u8fd9\u884c\u4e5f\u4f1a\u4ea7\u751f\u4e00\u4e2a\u81f4\u547d\u9519\u8bef\n$obj-&gt;printHello(); \/\/ \u8f93\u51fa Public\u3001Protected \u548c Private\n\/**\n* Define MyClass2\n*\/\nclass MyClass2 extends MyClass\n{\n\/\/ \u53ef\u4ee5\u5bf9 public \u548c protected \u8fdb\u884c\u91cd\u5b9a\u4e49\uff0c\u4f46 private \u800c\u4e0d\u80fd\nprotected $protected = 'Protected2';\nfunction printHello()\n{\necho $this-&gt;public;\necho $this-&gt;protected;\necho $this-&gt;private;\n}\n}\n$obj2 = new MyClass2();\necho $obj2-&gt;public; \/\/ \u8fd9\u884c\u80fd\u88ab\u6b63\u5e38\u6267\u884c\necho $obj2-&gt;private; \/\/ \u672a\u5b9a\u4e49 private\necho $obj2-&gt;protected; \/\/ \u8fd9\u884c\u4f1a\u4ea7\u751f\u4e00\u4e2a\u81f4\u547d\u9519\u8bef\n$obj2-&gt;printHello(); \/\/ \u8f93\u51fa Public\u3001Protected2 \u548c Undefined\n?&gt;<\/code><\/pre>\n<h3>\u65b9\u6cd5\u7684\u8bbf\u95ee\u63a7\u5236<\/h3>\n<p>\u7c7b\u4e2d\u7684\u65b9\u6cd5\u53ef\u4ee5\u88ab\u5b9a\u4e49\u4e3a\u516c\u6709\uff0c\u79c1\u6709\u6216\u53d7\u4fdd\u62a4\u3002\u5982\u679c\u6ca1\u6709\u8bbe\u7f6e\u8fd9\u4e9b\u5173\u952e\u5b57\uff0c\u5219\u8be5\u65b9\u516c\u6709<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n\/**\n* Define MyClass\n*\/\nclass MyClass\n{\n\/\/ \u58f0\u660e\u4e00\u4e2a\u516c\u6709\u7684\u6784\u9020\u51fd\u6570\npublic function __construct() { }\n\/\/ \u58f0\u660e\u4e00\u4e2a\u516c\u6709\u7684\u65b9\u6cd5\npublic function MyPublic() { }\n\/\/ \u58f0\u660e\u4e00\u4e2a\u53d7\u4fdd\u62a4\u7684\u65b9\u6cd5\nprotected function MyProtected() { }\n\/\/ \u58f0\u660e\u4e00\u4e2a\u79c1\u6709\u7684\u65b9\u6cd5\nprivate function MyPrivate() { }\n\/\/ \u6b64\u65b9\u6cd5\u4e3a\u516c\u6709\nfunction Foo()\n{\n$this-&gt;MyPublic();\n$this-&gt;MyProtected();\n$this-&gt;MyPrivate();\n}\n}\n$myclass = new MyClass;\n$myclass-&gt;MyPublic(); \/\/ \u8fd9\u884c\u80fd\u88ab\u6b63\u5e38\u6267\u884c\n$myclass-&gt;MyProtected(); \/\/ \u8fd9\u884c\u4f1a\u4ea7\u751f\u4e00\u4e2a\u81f4\u547d\u9519\u8bef\n$myclass-&gt;MyPrivate(); \/\/ \u8fd9\u884c\u4f1a\u4ea7\u751f\u4e00\u4e2a\u81f4\u547d\u9519\u8bef\n$myclass-&gt;Foo(); \/\/ \u516c\u6709\uff0c\u53d7\u4fdd\u62a4\uff0c\u79c1\u6709\u90fd\u53ef\u4ee5\u6267\u884c\n\/**\n* Define MyClass2\n*\/\nclass MyClass2 extends MyClass\n{\n\/\/ \u6b64\u65b9\u6cd5\u4e3a\u516c\u6709\nfunction Foo2()\n{\n$this-&gt;MyPublic();\n$this-&gt;MyProtected();\n$this-&gt;MyPrivate(); \/\/ \u8fd9\u884c\u4f1a\u4ea7\u751f\u4e00\u4e2a\u81f4\u547d\u9519\u8bef\n}\n}\n$myclass2 = new MyClass2;\n$myclass2-&gt;MyPublic(); \/\/ \u8fd9\u884c\u80fd\u88ab\u6b63\u5e38\u6267\u884c\n$myclass2-&gt;Foo2(); \/\/ \u516c\u6709\u7684\u548c\u53d7\u4fdd\u62a4\u7684\u90fd\u53ef\u6267\u884c\uff0c\u4f46\u79c1\u6709\u7684\u4e0d\u884c\nclass Bar\n{\npublic function test() {\n$this-&gt;testPrivate();\n$this-&gt;testPublic();\n}\npublic function testPublic() {\necho \"Bar::testPublicn\";\n}\nprivate function testPrivate() {\necho \"Bar::testPrivaten\";\n}\n}\nclass Foo extends Bar\n{\npublic function testPublic() {\necho \"Foo::testPublicn\";\n}\nprivate function testPrivate() {\necho \"Foo::testPrivaten\";\n}\n}\n$myFoo = new foo();\n$myFoo-&gt;test(); \/\/ Bar::testPrivate\n\/\/ Foo::testPublic\n?&gt;<\/code><\/pre>\n<h3>\u63a5\u53e3<\/h3>\n<p>\u4f7f\u7528\u63a5\u53e3\uff08interface\uff09\uff0c\u53ef\u4ee5\u6307\u5b9a\u67d0\u4e2a\u7c7b\u5fc5\u987b\u5b9e\u73b0\u54ea\u4e9b\u65b9\u6cd5\uff0c\u4f46\u4e0d\u9700\u8981\u5b9a\u4e49\u8fd9\u4e9b\u65b9\u6cd5\u7684\u5177\u4f53\u5185\u5bb9\u3002\u63a5\u53e3\u662f\u901a\u8fc7 interface \u5173\u952e\u5b57\u6765\u5b9a\u4e49\u7684\uff0c\u5c31\u50cf\u5b9a\u4e49\u4e00\u4e2a\u6807\u51c6\u7684\u7c7b\u4e00\u6837\uff0c\u4f46\u5176\u4e2d\u5b9a\u4e49\u6240\u6709\u7684\u65b9\u6cd5\u90fd\u662f\u7a7a\u7684\u3002<\/p>\n<p>\u63a5\u53e3\u4e2d\u5b9a\u4e49\u7684\u6240\u6709\u65b9\u6cd5\u90fd\u5fc5\u987b\u662f\u516c\u6709\uff0c\u8fd9\u662f\u63a5\u53e3\u7684\u7279\u6027\u3002<\/p>\n<p>\u8981\u5b9e\u73b0\u4e00\u4e2a\u63a5\u53e3\uff0c\u4f7f\u7528 implements \u64cd\u4f5c\u7b26\u3002\u7c7b\u4e2d\u5fc5\u987b\u5b9e\u73b0\u63a5\u53e3\u4e2d\u5b9a\u4e49\u7684\u6240\u6709\u65b9\u6cd5\uff0c\u5426\u5219\u4f1a\u62a5\u4e00\u4e2a\u81f4\u547d\u9519\u8bef\u3002\u7c7b\u53ef\u4ee5\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3\uff0c\u7528\u9017\u53f7\u6765\u5206\u9694\u591a\u4e2a\u63a5\u53e3\u7684\u540d\u79f0\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n\/\/ \u58f0\u660e\u4e00\u4e2a'iTemplate'\u63a5\u53e3\ninterface iTemplate\n{\npublic function setVariable($name, $var);\npublic function getHtml($template);\n}\n\/\/ \u5b9e\u73b0\u63a5\u53e3\nclass Template implements iTemplate\n{\nprivate $vars = array();\npublic function setVariable($name, $var)\n{\n$this-&gt;vars[$name] = $var;\n}\npublic function getHtml($template)\n{\nforeach($this-&gt;vars as $name =&gt; $value) {\n$template = str_replace('{' . $name . '}', $value, $template);\n}\nreturn $template;\n}\n}<\/code><\/pre>\n<h3>\u5e38\u91cf<\/h3>\n<p>\u53ef\u4ee5\u628a\u5728\u7c7b\u4e2d\u59cb\u7ec8\u4fdd\u6301\u4e0d\u53d8\u7684\u503c\u5b9a\u4e49\u4e3a\u5e38\u91cf\u3002\u5728\u5b9a\u4e49\u548c\u4f7f\u7528\u5e38\u91cf\u7684\u65f6\u5019\u4e0d\u9700\u8981\u4f7f<\/p>\n<p>\u7528 $ \u7b26\u53f7\u3002<\/p>\n<p>\u5e38\u91cf\u7684\u503c\u5fc5\u987b\u662f\u4e00\u4e2a\u5b9a\u503c\uff0c\u4e0d\u80fd\u662f\u53d8\u91cf\uff0c\u7c7b\u5c5e\u6027\uff0c\u6570\u5b66\u8fd0\u7b97\u7684\u7ed3\u679c\u6216\u51fd\u6570\u8c03\u7528\u3002<\/p>\n<p>\u81ea PHP 5.3.0 \u8d77\uff0c\u53ef\u4ee5\u7528\u4e00\u4e2a\u53d8\u91cf\u6765\u52a8\u6001\u8c03\u7528\u7c7b\u3002\u4f46\u8be5\u53d8\u91cf\u7684\u503c\u4e0d\u80fd\u4e3a\u5173\u952e\u5b57<\/p>\n<p>\uff08\u5982 self\uff0cparent \u6216 static\uff09\u3002<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nclass MyClass\n{\nconst constant = '\u5e38\u91cf\u503c';\nfunction showConstant() {\necho self::constant . PHP_EOL;\n}\n}\necho MyClass::constant . PHP_EOL;\n$classname = \"MyClass\";\necho $classname::constant . PHP_EOL; \/\/ \u81ea 5.3.0 \u8d77\n$class = new MyClass();\n$class-&gt;showConstant();\necho $class::constant . PHP_EOL; \/\/ \u81ea PHP 5.3.0 \u8d77\n?&gt;<\/code><\/pre>\n<h3>\u62bd\u8c61\u7c7b<\/h3>\n<p>\u4efb\u4f55\u4e00\u4e2a\u7c7b\uff0c\u5982\u679c\u5b83\u91cc\u9762\u81f3\u5c11\u6709\u4e00\u4e2a\u65b9\u6cd5\u662f\u88ab\u58f0\u660e\u4e3a\u62bd\u8c61\u7684\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7c7b\u5c31\u5fc5\u987b\u88ab\u58f0\u660e\u4e3a\u62bd\u8c61\u7684\u3002\u5b9a\u4e49\u4e3a\u62bd\u8c61\u7684\u7c7b\u4e0d\u80fd\u88ab\u5b9e\u4f8b\u5316\u3002\u88ab\u5b9a\u4e49\u4e3a\u62bd\u8c61\u7684\u65b9\u6cd5\u53ea\u662f\u58f0\u660e\u4e86\u5176\u8c03\u7528\u65b9\u5f0f\uff08\u53c2\u6570\uff09\uff0c\u4e0d\u80fd\u5b9a\u4e49\u5176\u5177\u4f53\u7684\u529f\u80fd\u5b9e\u73b0\u3002\u7ee7\u627f\u4e00\u4e2a\u62bd\u8c61\u7c7b\u7684\u65f6\u5019\uff0c\u5b50\u7c7b\u5fc5\u987b\u5b9a\u4e49\u7236\u7c7b\u4e2d\u7684\u6240\u6709\u62bd\u8c61\u65b9\u6cd5\uff1b\u53e6\u5916\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u7684\u8bbf\u95ee\u63a7\u5236\u5fc5\u987b\u548c\u7236\u7c7b\u4e2d\u4e00\u6837\uff08\u6216\u8005\u66f4\u4e3a\u5bbd\u677e\uff09\u3002\u4f8b\u5982\u67d0\u4e2a\u62bd\u8c61\u65b9\u6cd5\u88ab\u58f0\u660e\u4e3a\u53d7\u4fdd\u62a4\u7684\uff0c\u90a3\u4e48\u5b50\u7c7b\u4e2d\u5b9e\u73b0\u7684\u65b9\u6cd5\u5c31\u5e94\u8be5\u58f0\u660e\u4e3a\u53d7\u4fdd\u62a4\u7684\u6216\u8005\u516c\u6709\u7684\uff0c\u800c\u4e0d\u80fd\u5b9a\u4e49\u4e3a\u79c1\u6709\u7684\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nabstract class AbstractClass\n{\n\/\/ \u5f3a\u5236\u8981\u6c42\u5b50\u7c7b\u5b9a\u4e49\u8fd9\u4e9b\u65b9\u6cd5\nabstract protected function getValue();\nabstract protected function prefixValue($prefix);\n\/\/ \u666e\u901a\u65b9\u6cd5\uff08\u975e\u62bd\u8c61\u65b9\u6cd5\uff09\npublic function printOut() {\nprint $this-&gt;getValue() . PHP_EOL;\n}\n}\nclass ConcreteClass1 extends AbstractClass\n{\nprotected function getValue() {\nreturn \"ConcreteClass1\";\n}\npublic function prefixValue($prefix) {\nreturn \"{$prefix}ConcreteClass1\";\n}\n}\nclass ConcreteClass2 extends AbstractClass\n{\npublic function getValue() {\nreturn \"ConcreteClass2\";\n}\npublic function prefixValue($prefix) {\nreturn \"{$prefix}ConcreteClass2\";\n}\n}\n$class1 = new ConcreteClass1;\n$class1-&gt;printOut();\necho $class1-&gt;prefixValue('FOO_') . PHP_EOL;\n$class2 = new ConcreteClass2;\n$class2-&gt;printOut();\necho $class2-&gt;prefixValue('FOO_') . PHP_EOL;\n?&gt;<\/code><\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u4ee3\u7801\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p>ConcreteClass1<\/p>\n<p>FOO_ConcreteClass1<\/p>\n<p>ConcreteClass2<\/p>\n<p>FOO_ConcreteClass2<\/p>\n<p>\u6b64\u5916\uff0c\u5b50\u7c7b\u65b9\u6cd5\u53ef\u4ee5\u5305\u542b\u7236\u7c7b\u62bd\u8c61\u65b9\u6cd5\u4e2d\u4e0d\u5b58\u5728\u7684\u53ef\u9009\u53c2\u6570\u3002\u4f8b\u5982\uff0c\u5b50\u7c7b\u5b9a\u4e49\u4e86\u4e00\u4e2a\u53ef\u9009\u53c2\u6570\uff0c\u800c\u7236\u7c7b\u62bd\u8c61\u65b9\u6cd5\u7684\u58f0\u660e\u91cc\u6ca1\u6709\uff0c\u5219\u90fd\u662f\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\u7684\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nabstract class AbstractClass\n{\n\/\/ \u6211\u4eec\u7684\u62bd\u8c61\u65b9\u6cd5\u4ec5\u9700\u8981\u5b9a\u4e49\u9700\u8981\u7684\u53c2\u6570\nabstract protected function prefixName($name);\n}\nclass ConcreteClass extends AbstractClass\n{\n\/\/ \u6211\u4eec\u7684\u5b50\u7c7b\u53ef\u4ee5\u5b9a\u4e49\u7236\u7c7b\u7b7e\u540d\u4e2d\u4e0d\u5b58\u5728\u7684\u53ef\u9009\u53c2\u6570\npublic function prefixName($name, $separator = \".\") {\nif ($name == \"Pacman\") {\n$prefix = \"Mr\";\n} elseif ($name == \"Pacwoman\") {\n$prefix = \"Mrs\";\n} else {\n$prefix = \"\";\n}\nreturn \"{$prefix}{$separator} {$name}\";\n}\n}\n$class = new ConcreteClass;\necho $class-&gt;prefixName(\"Pacman\"), \"n\";\necho $class-&gt;prefixName(\"Pacwoman\"), \"n\";\n?&gt;<\/code><\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p>Mr. Pacman<\/p>\n<p>Mrs. Pacwoman<\/p>\n<h3>\u63a5\u53e3\u4e0e\u62bd\u8c61\u7c7b<\/h3>\n<ol>\n<li>\u63a5\u53e3<\/li>\n<\/ol>\n<p>\uff081\uff09\u5bf9\u63a5\u53e3\u7684\u4f7f\u7528\u662f\u901a\u8fc7\u5173\u952e\u5b57 implements<\/p>\n<p>\uff082\uff09\u63a5\u53e3\u4e0d\u80fd\u5b9a\u4e49\u6210\u5458\u53d8\u91cf\uff08\u5305\u62ec\u7c7b\u9759\u6001\u53d8\u91cf\uff09\uff0c\u80fd\u5b9a\u4e49\u5e38\u91cf<\/p>\n<p>\uff083\uff09\u5b50\u7c7b\u5fc5\u987b\u5b9e\u73b0\u63a5\u53e3\u5b9a\u4e49\u7684\u6240\u6709\u65b9\u6cd5<\/p>\n<p>\uff084\uff09\u63a5\u53e3\u53ea\u80fd\u5b9a\u4e49\u4e0d\u80fd\u5b9e\u73b0\u8be5\u65b9\u6cd5<\/p>\n<p>\uff085\uff09\u63a5\u53e3\u6ca1\u6709\u6784\u9020\u51fd\u6570<\/p>\n<p>\uff086\uff09\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u548c\u5b9e\u73b0\u5b83\u7684\u7c7b\u9ed8\u8ba4\u90fd\u662f public \u7c7b\u578b\u7684<\/p>\n<ol start=\"2\">\n<li>\u62bd\u8c61\u7c7b<\/li>\n<\/ol>\n<p>\uff081\uff09\u5bf9\u62bd\u8c61\u7c7b\u7684\u4f7f\u7528\u662f\u901a\u8fc7\u5173\u952e\u5b57 extends<\/p>\n<p>\uff082\uff09\u4e0d\u80fd\u88ab\u5b9e\u4f8b\u5316\uff0c\u53ef\u4ee5\u5b9a\u4e49\u5b50\u7c7b\u5fc5\u987b\u5b9e\u73b0\u7684\u65b9\u6cd5<\/p>\n<p>\uff083\uff09\u5b50\u7c7b\u5fc5\u987b\u5b9a\u4e49\u7236\u7c7b\u4e2d\u7684\u6240\u6709\u62bd\u8c61\u65b9\u6cd5\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u7684\u8bbf\u95ee\u63a7\u5236\u5fc5\u987b\u548c\u7236\u7c7b\u4e2d<\/p>\n<p>\u4e00\u6837\uff08\u6216\u8005\u66f4\u4e3a\u5bbd\u677e\uff09<\/p>\n<p>\uff084\uff09\u5982\u4e00\u4e2a\u7c7b\u4e2d\u6709\u4e00\u4e2a\u62bd\u8c61\u65b9\u6cd5\uff0c\u5219\u8be5\u7c7b\u5fc5\u987b\u5b9a\u4e49\u4e3a\u62bd\u8c61\u7c7b<\/p>\n<p>\uff085\uff09\u62bd\u8c61\u7c7b\u53ef\u4ee5\u6709\u6784\u9020\u51fd\u6570<\/p>\n<p>\uff086\uff09\u62bd\u8c61\u7c7b\u4e2d\u7684\u65b9\u6cd5\u53ef\u4ee5\u4f7f\u7528 private,protected,public \u6765\u4fee\u9970\u3002<\/p>\n<p>\uff087\uff09\u4e00\u4e2a\u7c7b\u53ef\u4ee5\u540c\u65f6\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3\uff0c\u4f46\u4e00\u4e2a\u7c7b\u53ea\u80fd\u7ee7\u627f\u4e8e\u4e00\u4e2a\u62bd\u8c61\u7c7b\u3002<\/p>\n<h3>Static \u5173\u952e\u5b57<\/h3>\n<p>\u58f0\u660e\u7c7b\u5c5e\u6027\u6216\u65b9\u6cd5\u4e3a static(\u9759\u6001)\uff0c\u5c31\u53ef\u4ee5\u4e0d\u5b9e\u4f8b\u5316\u7c7b\u800c\u76f4\u63a5\u8bbf\u95ee\u3002<\/p>\n<p>\u9759\u6001\u5c5e\u6027\u4e0d\u80fd\u901a\u8fc7\u4e00\u4e2a\u7c7b\u5df2\u5b9e\u4f8b\u5316\u7684\u5bf9\u8c61\u6765\u8bbf\u95ee\uff08\u4f46\u9759\u6001\u65b9\u6cd5\u53ef\u4ee5\uff09\u3002<\/p>\n<p>\u7531\u4e8e\u9759\u6001\u65b9\u6cd5\u4e0d\u9700\u8981\u901a\u8fc7\u5bf9\u8c61\u5373\u53ef\u8c03\u7528\uff0c\u6240\u4ee5\u4f2a\u53d8\u91cf $this \u5728\u9759\u6001\u65b9\u6cd5\u4e2d\u4e0d\u53ef\u7528\u3002<\/p>\n<p>\u9759\u6001\u5c5e\u6027\u4e0d\u53ef\u4ee5\u7531\u5bf9\u8c61\u901a\u8fc7 -&gt; \u64cd\u4f5c\u7b26\u6765\u8bbf\u95ee\u3002<\/p>\n<p>\u81ea PHP 5.3.0 \u8d77\uff0c\u53ef\u4ee5\u7528\u4e00\u4e2a\u53d8\u91cf\u6765\u52a8\u6001\u8c03\u7528\u7c7b\u3002\u4f46\u8be5\u53d8\u91cf\u7684\u503c\u4e0d\u80fd\u4e3a\u5173\u952e\u5b57 self\uff0c<\/p>\n<p>parent \u6216 static\u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nclass Foo {\npublic static $my_static = 'foo';\npublic function staticValue() {\nreturn self::$my_static;\n}\n}\nprint Foo::$my_static . PHP_EOL;\n$foo = new Foo();\nprint $foo-&gt;staticValue() . PHP_EOL;\n?&gt;<\/code><\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u7a0b\u5e8f\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p>foo<\/p>\n<p>Foo<\/p>\n<h3>Final \u5173\u952e\u5b57<\/h3>\n<p>PHP 5 \u65b0\u589e\u4e86\u4e00\u4e2a final \u5173\u952e\u5b57\u3002\u5982\u679c\u7236\u7c7b\u4e2d\u7684\u65b9\u6cd5\u88ab\u58f0\u660e\u4e3a final\uff0c\u5219\u5b50\u7c7b\u65e0\u6cd5\u8986\u76d6\u8be5\u65b9\u6cd5\u3002\u5982\u679c\u4e00\u4e2a\u7c7b\u88ab\u58f0\u660e\u4e3a final\uff0c\u5219\u4e0d\u80fd\u88ab\u7ee7\u627f\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u6267\u884c\u4f1a\u62a5\u9519\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nclass BaseClass {\npublic function test() {\necho \"BaseClass::test() called\" . PHP_EOL;\n}\nfinal public function moreTesting() {\necho \"BaseClass::moreTesting() called\" . PHP_EOL;\n}\n}\nclass ChildClass extends BaseClass {\npublic function moreTesting() {\necho \"ChildClass::moreTesting() called\" . PHP_EOL;\n}\n}<\/code><\/pre>\n<p>\/\/ \u62a5\u9519\u4fe1\u606f Fatal error: Cannot override final method BaseClass::moreTesting()<\/p>\n<p>?&gt;<\/p>\n<p>\u8c03\u7528\u7236\u7c7b\u6784\u9020\u65b9\u6cd5<\/p>\n<p>PHP \u4e0d\u4f1a\u5728\u5b50\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u4e2d\u81ea\u52a8\u7684\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u3002\u8981\u6267\u884c\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\uff0c\u9700\u8981\u5728\u5b50\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u4e2d\u8c03\u7528 parent::__construct() \u3002<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\nclass BaseClass {\nfunction __construct() {\nprint \"BaseClass \u7c7b\u4e2d\u6784\u9020\u65b9\u6cd5\" . PHP_EOL;\n}\n}\nclass SubClass extends BaseClass {\nfunction __construct() {\nparent::__construct(); \/\/ \u5b50\u7c7b\u6784\u9020\u65b9\u6cd5\u4e0d\u80fd\u81ea\u52a8\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\nprint \"SubClass \u7c7b\u4e2d\u6784\u9020\u65b9\u6cd5\" . PHP_EOL;\n}\n}\nclass OtherSubClass extends BaseClass {\n\/\/ \u7ee7\u627f BaseClass \u7684\u6784\u9020\u65b9\u6cd5\n}\n\/\/ \u8c03\u7528 BaseClass \u6784\u9020\u65b9\u6cd5\n$obj = new BaseClass();\n\/\/ \u8c03\u7528 BaseClass\u3001SubClass \u6784\u9020\u65b9\u6cd5\n$obj = new SubClass();\n\/\/ \u8c03\u7528 BaseClass \u6784\u9020\u65b9\u6cd5\n$obj = new OtherSubClass();\n?&gt;<\/code><\/pre>\n<p>\u6267\u884c\u4ee5\u4e0a\u7a0b\u5e8f\uff0c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n<p>BaseClass \u7c7b\u4e2d\u6784\u9020\u65b9\u6cd5<\/p>\n<p>BaseClass \u7c7b\u4e2d\u6784\u9020\u65b9\u6cd5<\/p>\n<p>SubClass \u7c7b\u4e2d\u6784\u9020\u65b9\u6cd5<\/p>\n<p>BaseClass \u7c7b\u4e2d\u6784\u9020\u65b9\u6cd5<\/p>\n<h1>PHP \u8d85\u7ea7\u5168\u5c40\u53d8\u91cf<\/h1>\n<p>PHP \u8d85\u7ea7\u5168\u5c40\u53d8\u91cf\u5217\u8868\uff1a<\/p>\n<p>$GLOBALS \u4e00\u4e2a\u5305\u542b\u4e86\u5168\u90e8\u53d8\u91cf\u7684\u5168\u5c40\u7ec4\u5408\u6570\u7ec4\u3002\u53d8\u91cf\u7684\u540d\u5b57\u5c31\u662f\u6570\u7ec4\u7684\u952e\u3002<\/p>\n<p>$_SERVER \u4e00\u4e2a\u5305\u542b\u4e86\u8bf8\u5982\u5934\u4fe1\u606f(header)\u3001\u8def\u5f84(path)\u3001\u4ee5\u53ca\u811a\u672c\u4f4d\u7f6e(script locations)\u7b49\u7b49\u4fe1\u606f\u7684\u6570\u7ec4<\/p>\n<p>$_REQUEST \u7528\u4e8e\u6536\u96c6 HTML \u8868\u5355\u63d0\u4ea4\u7684\u6570\u636e\u3002\u5b83\u53ef\u4ee5\u83b7\u53d6 cookie get post<\/p>\n<p>$_POST \u5e7f\u6cdb\u5e94\u7528\u4e8e\u6536\u96c6\u8868\u5355\u6570\u636e\uff0c\u5728 HTML form \u6807\u7b7e\u7684\u6307\u5b9a\u8be5\u5c5e\u6027\uff1a&quot;method=&quot;post&quot;\u3002<\/p>\n<p>$_GET \u5e7f\u6cdb\u5e94\u7528\u4e8e\u6536\u96c6\u8868\u5355\u6570\u636e\uff0c\u5728 HTML form \u6807\u7b7e\u7684\u6307\u5b9a\u8be5\u5c5e\u6027\uff1a&quot;method=&quot;get&quot;\u3002<\/p>\n<p>Array [ ]<\/p>\n<p>$_FILES<\/p>\n<p>$_ENV<\/p>\n<p>$_COOKIE<\/p>\n<p>$_SESSION<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n\/\/ php \u9884\u5b9a\u4e49\u65b9\u6cd5\necho \"n\", $GLOBALS['y'];\necho \"n\", $_SERVER['PHP_SELF'];\necho \"n\", $_SERVER['SERVER_NAME'];\necho \"n\", $_SERVER['HTTP_HOST'];\n?&gt;<\/code><\/pre>\n<h1>PHP Include \u6587\u4ef6<\/h1>\n<p>\u670d\u52a1\u5668\u7aef\u5305\u542b (SSI) \u7528\u4e8e\u521b\u5efa\u53ef\u5728\u591a\u4e2a\u9875\u9762\u91cd\u590d\u4f7f\u7528\u7684\u51fd\u6570\u3001\u9875\u7709\u3001\u9875\u811a\u6216\u5143\u7d20\u3002<\/p>\n<p>include \uff08\u6216 require\uff09\u8bed\u53e5\u4f1a\u83b7\u53d6\u6307\u5b9a\u6587\u4ef6\u4e2d\u5b58\u5728\u7684\u6240\u6709\u6587\u672c\/\u4ee3\u7801\/\u6807\u8bb0\uff0c\u5e76\u590d\u5236\u5230\u4f7f\u7528 include \u8bed\u53e5\u7684\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u5305\u542b\u6587\u4ef6\u5f88\u6709\u7528\uff0c\u5982\u679c\u60a8\u9700\u8981\u5728\u7f51\u7ad9\u7684\u591a\u5f20\u9875\u9762\u4e0a\u5f15\u7528\u76f8\u540c\u7684 PHP\u3001HTML \u6216\u6587\u672c\u7684\u8bdd\u3002<\/p>\n<p>PHP include \u548c require \u8bed\u53e5<\/p>\n<p>\u901a\u8fc7 include \u6216 require \u8bed\u53e5\uff0c\u53ef\u4ee5\u5c06 PHP \u6587\u4ef6\u7684\u5185\u5bb9\u63d2\u5165\u53e6\u4e00\u4e2a PHP \u6587\u4ef6\uff08\u5728\u670d\u52a1\u5668\u6267\u884c\u5b83\u4e4b\u524d\uff09\u3002<\/p>\n<p>include \u548c require \u8bed\u53e5\u662f\u76f8\u540c\u7684\uff0c\u9664\u4e86\u9519\u8bef\u5904\u7406\u65b9\u9762\uff1a<\/p>\n<p>require \u4f1a\u751f\u6210\u81f4\u547d\u9519\u8bef\uff08E_COMPILE_ERROR\uff09\u5e76\u505c\u6b62\u811a\u672c<\/p>\n<p>include \u53ea\u751f\u6210\u8b66\u544a\uff08E_WARNING\uff09\uff0c\u5e76\u4e14\u811a\u672c\u4f1a\u7ee7\u7eed<\/p>\n<p>\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u5e0c\u671b\u7ee7\u7eed\u6267\u884c\uff0c\u5e76\u5411\u7528\u6237\u8f93\u51fa\u7ed3\u679c\uff0c\u5373\u4f7f\u5305\u542b\u6587\u4ef6\u5df2\u4e22\u5931\uff0c\u90a3\u4e48\u8bf7\u4f7f\u7528 include\u3002\u5426\u5219\uff0c\u5728\u6846\u67b6\u3001CMS \u6216\u8005\u590d\u6742\u7684 PHP \u5e94\u7528\u7a0b\u5e8f\u7f16\u7a0b\u4e2d\uff0c\u8bf7\u59cb\u4f7f\u7528 require \u5411\u6267\u884c\u6d41\u5f15\u7528\u5173\u952e\u6587\u4ef6\u3002\u8fd9\u6709\u52a9\u4e8e\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u5b89\u5168\u6027\u548c\u5b8c\u6574\u6027\uff0c\u5728\u67d0\u4e2a\u5173\u952e\u6587\u4ef6\u610f\u5916\u4e22\u5931\u7684\u60c5\u51b5\u4e0b\u3002\u5305\u542b\u6587\u4ef6\u7701\u53bb\u4e86\u5927\u91cf\u7684\u5de5\u4f5c\u3002\u8fd9\u610f\u5473\u7740\u60a8\u53ef\u4ee5\u4e3a\u6240\u6709\u9875\u9762\u521b\u5efa\u6807\u51c6\u9875\u5934\u3001\u9875\u811a\u6216\u8005\u83dc\u5355\u6587\u4ef6\u3002\u7136\u540e\uff0c\u5728\u9875\u5934\u9700\u8981\u66f4\u65b0\u65f6\uff0c\u60a8\u53ea\u9700\u66f4\u65b0\u8fd9\u4e2a\u9875\u5934\u5305\u542b\u6587\u4ef6\u5373\u53ef\u3002<\/p>\n<p>\u8bed\u6cd5<\/p>\n<p>include &#8216;filename&#8217;;<\/p>\n<p>\u6216<\/p>\n<p>require &#8216;filename&#8217;;<\/p>\n<h1>PHP \u6587\u4ef6\u5904\u7406<\/h1>\n<h2>PHP \u64cd\u4f5c\u6587\u4ef6<\/h2>\n<p>PHP \u62e5\u6709\u7684\u591a\u79cd\u51fd\u6570\u53ef\u4f9b\u521b\u5efa\u3001\u8bfb\u53d6\u3001\u4e0a\u4f20\u4ee5\u53ca\u7f16\u8f91\u6587\u4ef6\u3002<\/p>\n<p>\u6ce8\u610f\uff1a\u8bf7\u8c28\u614e\u64cd\u4f5c\u6587\u4ef6\uff01<\/p>\n<p>\u5f53\u60a8\u64cd\u4f5c\u6587\u4ef6\u65f6\u5fc5\u987b\u975e\u5e38\u5c0f\u5fc3\u3002\u5982\u679c\u60a8\u64cd\u4f5c\u5931\u8bef\uff0c\u53ef\u80fd\u4f1a\u9020\u6210\u975e\u5e38\u4e25\u91cd\u7684\u7834\u574f\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u9519\u8bef\u662f\uff1a<\/p>\n<p>\u7f16\u8f91\u9519\u8bef\u7684\u6587\u4ef6<\/p>\n<p>\u88ab\u5783\u573e\u6570\u636e\u586b\u6ee1\u786c\u76d8<\/p>\n<p>\u610f\u5916\u5220\u9664\u6587\u4ef6\u5185\u5bb9<\/p>\n<p>PHP readfile() \u51fd\u6570<\/p>\n<p>readfile() \u51fd\u6570\u8bfb\u53d6\u6587\u4ef6\uff0c\u5e76\u628a\u5b83\u5199\u5165\u8f93\u51fa\u7f13\u51b2\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a &quot;webdictionary.txt&quot; \u7684\u6587\u672c\u6587\u4ef6\uff0c\u5b58\u653e\u5728\u670d\u52a1\u5668\u4e0a\uff0c\u5c31\u50cf\u8fd9<\/p>\n<p>\u6837\uff1a<\/p>\n<p>AJAX = Asynchronous JavaScript and XML<\/p>\n<p>CSS = Cascading Style Sheets<\/p>\n<p>HTML = Hyper Text Markup Language<\/p>\n<p>PHP = PHP Hypertext Preprocessor<\/p>\n<p>SQL = Structured Query Language<\/p>\n<p>SVG = Scalable Vector Graphics<\/p>\n<p>XML = EXtensible Markup Language<\/p>\n<p>\u8bfb\u53d6\u6b64\u6587\u4ef6\u5e76\u5199\u5230\u8f93\u51fa\u6d41\u7684 PHP \u4ee3\u7801\u5982\u4e0b\uff08\u5982\u8bfb\u53d6\u6210\u529f\u5219 readfile() \u51fd\u6570\u8fd4\u56de<\/p>\n<p>\u5b57\u8282\u6570\uff09\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\necho readfile(\"webdictionary.txt\");\n?&gt;<\/code><\/pre>\n<h2>PHP \u6587\u4ef6\u6253\u5f00\/\u8bfb\u53d6\/\u5173\u95ed<\/h2>\n<p>\u5982\u4f55\u5728\u670d\u52a1\u5668\u4e0a\u6253\u5f00\u3001\u8bfb\u53d6\u4ee5\u53ca\u5173\u95ed\u6587\u4ef6\u3002<\/p>\n<p>PHP Open File &#8211; fopen()<\/p>\n<p>\u6253\u5f00\u6587\u4ef6\u7684\u66f4\u597d\u7684\u65b9\u6cd5\u662f\u901a\u8fc7 fopen() \u51fd\u6570\u3002\u6b64\u51fd\u6570\u4e3a\u60a8\u63d0\u4f9b\u6bd4 readfile() \u51fd\u6570<\/p>\n<p>\u66f4\u591a\u7684\u9009\u9879\u3002<\/p>\n<p>\u5728\u8bfe\u7a0b\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u6587\u672c\u6587\u4ef6 &quot;webdictionary.txt&quot;\uff1a<\/p>\n<p>AJAX = Asynchronous JavaScript and XML<\/p>\n<p>CSS = Cascading Style Sheets<\/p>\n<p>HTML = Hyper Text Markup Language<\/p>\n<p>PHP = PHP Hypertext Preprocessor<\/p>\n<p>SQL = Structured Query Language<\/p>\n<p>SVG = Scalable Vector Graphics<\/p>\n<p>XML = EXtensible Markup Language<\/p>\n<p>fopen() \u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5305\u542b\u88ab\u6253\u5f00\u7684\u6587\u4ef6\u540d\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u89c4\u5b9a\u6253\u5f00\u6587\u4ef6\u7684\u6a21\u5f0f\u3002<\/p>\n<p>\u5982\u679c fopen() \u51fd\u6570\u672a\u80fd\u6253\u5f00\u6307\u5b9a\u7684\u6587\u4ef6\uff0c\u4e0b\u9762\u7684\u4f8b\u5b50\u4f1a\u751f\u6210\u4e00\u6bb5\u6d88\u606f\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$myfile = fopen(\"webdictionary.txt\", \"r\") or die(\"Unable to open file!\");\necho fread($myfile,filesize(\"webdictionary.txt\"));\nfclose($myfile);\n?&gt;<\/code><\/pre>\n<p>\u63d0\u793a\uff1a\u6211\u4eec\u63a5\u4e0b\u6765\u5c06\u5b66\u4e60 fread() \u4ee5\u53ca fclose() \u51fd\u6570\u3002<\/p>\n<p>\u6587\u4ef6\u4f1a\u4ee5\u5982\u4e0b\u6a21\u5f0f\u4e4b\u4e00\u6253\u5f00\uff1a<\/p>\n<p><img loading="lazy" decoding="async" decoding=\"async\"  src=\"https:\/\/www.youvii.site\/wp-content\/themes\/lolimeow-lolimeowV13.13\/assets\/images\/loading.gif\" data-src=\"https:\/\/cdn.picui.cn\/vip\/2025\/10\/24\/68faeac9b64f4.png\" class=\"lazy\" loading=\"lazy\" alt=\"1745379026679-cbf273c9-f564-4414-b60e-ba574b96027e.png\" \/><\/p>\n<h3>PHP \u8bfb\u53d6\u6587\u4ef6 &#8211; fread()<\/h3>\n<p>fread() \u51fd\u6570\u8bfb\u53d6\u6253\u5f00\u7684\u6587\u4ef6\u3002<\/p>\n<p>fread() \u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5305\u542b\u5f85\u8bfb\u53d6\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u89c4\u5b9a\u5f85\u8bfb\u53d6\u7684\u6700\u5927\u5b57\u8282\u6570\u3002<\/p>\n<p>\u5982\u4e0b PHP \u4ee3\u7801\u628a &quot;webdictionary.txt&quot; \u6587\u4ef6\u8bfb\u81f3\u7ed3\u5c3e\uff1a<\/p>\n<p>fread($myfile,filesize(&quot;webdictionary.txt&quot;));<\/p>\n<p>PHP \u5173\u95ed\u6587\u4ef6 &#8211; fclose()<\/p>\n<p>fclose() \u51fd\u6570\u7528\u4e8e\u5173\u95ed\u6253\u5f00\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u6ce8\u91ca\uff1a\u7528\u5b8c\u6587\u4ef6\u540e\u628a\u5b83\u4eec\u5168\u90e8\u5173\u95ed\u662f\u4e00\u4e2a\u826f\u597d\u7684\u7f16\u7a0b\u4e60\u60ef\u3002\u60a8\u5e76\u4e0d\u60f3\u6253\u5f00\u7684\u6587\u4ef6\u5360\u7528\u60a8\u7684\u670d\u52a1\u5668\u8d44\u6e90\u3002<\/p>\n<p>fclose() \u9700\u8981\u5f85\u5173\u95ed\u6587\u4ef6\u7684\u540d\u79f0\uff08\u6216\u8005\u5b58\u6709\u6587\u4ef6\u540d\u7684\u53d8\u91cf\uff09\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$myfile = fopen(\"webdictionary.txt\", \"r\");\n\/\/ some code to be executed....\nfclose($myfile);\n?&gt;<\/code><\/pre>\n<p>PHP \u8bfb\u53d6\u5355\u884c\u6587\u4ef6 &#8211; fgets()<\/p>\n<p>fgets() \u51fd\u6570\u7528\u4e8e\u4ece\u6587\u4ef6\u8bfb\u53d6\u5355\u884c\u3002<\/p>\n<p>\u4e0b\u4f8b\u8f93\u51fa &quot;webdictionary.txt&quot; \u6587\u4ef6\u7684\u9996\u884c\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$myfile = fopen(\"webdictionary.txt\", \"r\") or die(\"Unable to open file!\");\necho fgets($myfile);\nfclose($myfile);\n?&gt;<\/code><\/pre>\n<p>\u8fd0\u884c\u5b9e\u4f8b<\/p>\n<p>\u6ce8\u91ca\uff1a\u8c03\u7528 fgets() \u51fd\u6570\u4e4b\u540e\uff0c\u6587\u4ef6\u6307\u9488\u4f1a\u79fb\u52a8\u5230\u4e0b\u4e00\u884c\u3002<\/p>\n<p>PHP \u68c0\u67e5 End-Of-File &#8211; feof()<\/p>\n<p>feof() \u51fd\u6570\u68c0\u67e5\u662f\u5426\u5df2\u5230\u8fbe &quot;end-of-file&quot; (EOF)\u3002<\/p>\n<p>feof() \u5bf9\u4e8e\u904d\u5386\u672a\u77e5\u957f\u5ea6\u7684\u6570\u636e\u5f88\u6709\u7528\u3002<\/p>\n<p>feof() \u51fd\u6570\u68c0\u67e5\u662f\u5426\u5df2\u5230\u8fbe\u6587\u4ef6\u672b\u5c3e(EOF)<\/p>\n<p>\u4e0b\u4f8b\u9010\u884c\u8bfb\u53d6 &quot;webdictionary.txt&quot; \u6587\u4ef6\uff0c\u76f4\u5230 end-of-file\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$myfile = fopen(\"webdictionary.txt\", \"r\") or die(\"Unable to open file!\");\n\/\/ \u8f93\u51fa\u5355\u884c\u76f4\u5230 end-of-file\nwhile(!feof($myfile)) {\necho fgets($myfile) . \"&lt;br&gt;\";\n}\nfclose($myfile);\n?&gt;<\/code><\/pre>\n<p>\u8fd0\u884c\u5b9e\u4f8b<\/p>\n<p>PHP \u8bfb\u53d6\u5355\u5b57\u7b26 &#8211; fgetc()<\/p>\n<p>fgetc() \u51fd\u6570\u7528\u4e8e\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5355\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>\u4e0b\u4f8b\u9010\u5b57\u7b26\u8bfb\u53d6 &quot;webdictionary.txt&quot; \u6587\u4ef6\uff0c\u76f4\u5230 end-of-file\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$myfile = fopen(\"webdictionary.txt\", \"r\") or die(\"Unable to open file!\");\n\/\/ \u8f93\u51fa\u5355\u5b57\u7b26\u76f4\u5230 end-of-file\nwhile(!feof($myfile)) {\necho fgetc($myfile);\n}\nfclose($myfile);\n?&gt;<\/code><\/pre>\n<p>\u8fd0\u884c\u5b9e\u4f8b<\/p>\n<p>\u6ce8\u91ca\uff1a\u5728\u8c03\u7528 fgetc() \u51fd\u6570\u4e4b\u540e\uff0c\u6587\u4ef6\u6307\u9488\u4f1a\u79fb\u52a8\u5230\u4e0b\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>\u5728\u672c\u8282\u4e2d\uff0c\u6211\u4eec\u5c06\u4e3a\u60a8\u8bb2\u89e3\u5982\u4f55\u5728\u670d\u52a1\u5668\u4e0a\u521b\u5efa\u5e76\u5199\u5165\u6587\u4ef6\u3002<\/p>\n<h3>PHP \u521b\u5efa\u6587\u4ef6 &#8211; fopen()<\/h3>\n<p>fopen() \u51fd\u6570\u4e5f\u7528\u4e8e\u521b\u5efa\u6587\u4ef6\u3002\u4e5f\u8bb8\u6709\u70b9\u6df7\u4e71\uff0c\u4f46\u662f\u5728 PHP \u4e2d\uff0c\u521b\u5efa\u6587\u4ef6\u6240\u7528\u7684\u51fd\u6570\u4e0e\u6253\u5f00\u6587\u4ef6\u7684\u76f8\u540c\u3002<\/p>\n<p>\u5982\u679c\u60a8\u7528 fopen() \u6253\u5f00\u5e76\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\uff0c\u6b64\u51fd\u6570\u4f1a\u521b\u5efa\u6587\u4ef6\uff0c\u5047\u5b9a\u6587\u4ef6\u88ab\u6253\u5f00\u4e3a\u5199\u5165\uff08w\uff09\u6216\u589e\u52a0\uff08a\uff09\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u4f8b\u5b50\u521b\u5efa\u540d\u4e3a &quot;testfile.txt&quot; \u7684\u65b0\u6587\u4ef6\u3002\u6b64\u6587\u4ef6\u5c06\u88ab\u521b\u5efa\u4e8e PHP \u4ee3\u7801\u6240\u5728\u7684\u76f8\u540c\u76ee\u5f55\u4e2d\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<p>$myfile = fopen(&quot;testfile.txt&quot;, &quot;w&quot;)<\/p>\n<p>PHP \u6587\u4ef6\u6743\u9650<\/p>\n<p>\u5982\u679c\u60a8\u8bd5\u56fe\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u65f6\u53d1\u751f\u9519\u8bef\uff0c\u8bf7\u68c0\u67e5\u60a8\u662f\u5426\u6709\u5411\u786c\u76d8\u5199\u5165\u4fe1\u606f\u7684 PHP\u6587\u4ef6\u8bbf\u95ee\u6743\u9650\u3002<\/p>\n<h3>PHP \u5199\u5165\u6587\u4ef6 &#8211; fwrite()<\/h3>\n<p>fwrite() \u51fd\u6570\u7528\u4e8e\u5199\u5165\u6587\u4ef6\u3002<\/p>\n<p>fwrite() \u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u5305\u542b\u8981\u5199\u5165\u7684\u6587\u4ef6\u7684\u6587\u4ef6\u540d\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u88ab\u5199\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u4f8b\u5b50\u628a\u59d3\u540d\u5199\u5165\u540d\u4e3a &quot;newfile.txt&quot; \u7684\u65b0\u6587\u4ef6\u4e2d\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$myfile = fopen(\"newfile.txt\", \"w\") or die(\"Unable to open file!\");\n$txt = \"Bill Gatesn\";\nfwrite($myfile, $txt);\n$txt = \"Steve Jobsn\";\nfwrite($myfile, $txt);\nfclose($myfile);\n?&gt;<\/code><\/pre>\n<p>\u8bf7\u6ce8\u610f\uff0c\u6211\u4eec\u5411\u6587\u4ef6 &quot;newfile.txt&quot; \u5199\u4e86\u4e24\u6b21\u3002\u5728\u6bcf\u6b21\u6211\u4eec\u5411\u6587\u4ef6\u5199\u5165\u65f6\uff0c\u5728\u6211\u4eec\u53d1\u9001\u7684\u5b57\u7b26\u4e32 $txt \u4e2d\uff0c\u7b2c\u4e00\u6b21\u5305\u542b &quot;Bill Gates&quot;\uff0c\u7b2c\u4e8c\u6b21\u5305\u542b &quot;Steve Jobs&quot;\u3002\u5728\u5199\u5165\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u4f7f\u7528 fclose() \u51fd\u6570\u6765\u5173\u95ed\u6587\u4ef6\u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u6253\u5f00 &quot;newfile.txt&quot; \u6587\u4ef6\uff0c\u5b83\u5e94\u8be5\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p>Bill Gates<\/p>\n<p>Steve Jobs<\/p>\n<p>PHP \u8986\u76d6\uff08Overwriting\uff09<\/p>\n<p>\u5982\u679c\u73b0\u5728 &quot;newfile.txt&quot; \u5305\u542b\u4e86\u4e00\u4e9b\u6570\u636e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c55\u793a\u5728\u5199\u5165\u5df2\u6709\u6587\u4ef6\u65f6\u53d1\u751f\u7684\u7684\u4e8b\u60c5\u3002\u6240\u6709\u5df2\u5b58\u5728\u7684\u6570\u636e\u4f1a\u88ab\u64e6\u9664\u5e76\u4ee5\u4e00\u4e2a\u65b0\u6587\u4ef6\u5f00\u59cb\u3002\u5728\u4e0b\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6253\u5f00\u4e00\u4e2a\u5df2\u5b58\u5728\u7684\u6587\u4ef6 &quot;newfile.txt&quot;\uff0c\u5e76\u5411\u5176\u4e2d\u5199\u5165\u4e86\u4e00\u4e9b\u65b0\u6570\u636e\uff1a<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$myfile = fopen(\"newfile.txt\", \"w\") or die(\"Unable to open file!\");\n$txt = \"Mickey Mousen\";\nfwrite($myfile, $txt);\n$txt = \"Minnie Mousen\";\nfwrite($myfile, $txt);\nfclose($myfile);\n?&gt;<\/code><\/pre>\n<p>\u5982\u679c\u73b0\u5728\u6211\u4eec\u6253\u5f00\u8fd9\u4e2a &quot;newfile.txt&quot; \u6587\u4ef6\uff0cBill \u548c Steve \u90fd\u5df2\u6d88\u5931\uff0c\u53ea\u5269\u4e0b\u6211\u4eec\u521a\u5199\u5165\u7684\u6570\u636e\uff1a<\/p>\n<p>Mickey Mouse<\/p>\n<p>Minnie Mouse<\/p>\n<h2>\u6587\u4ef6\u7684 \u590d\u5236 \u5220\u9664 \u91cd\u540d<\/h2>\n<p>php \u6587\u4ef6\u91cd\u547d\u540d\uff1a\u51fd\u6570 rename()\u3002<\/p>\n<p>php \u6587\u4ef6\u590d\u5236\uff1a\u51fd\u6570 copy();<\/p>\n<p>php \u6587\u4ef6\u5220\u9664\uff1a\u51fd\u6570 unlink();<\/p>\n<h2>\u6587\u4ef6\u7684\u5224\u65ad<\/h2>\n<p>file_exists() \u5224\u65ad\u6587\u4ef6\u662f\u5426\u5b58\u5728<\/p>\n<p>is_file() \u662f\u5426\u4e3a\u6587\u4ef6\u3002<\/p>\n<h1>PHP \u83b7\u53d6\u6587\u4ef6\u5c5e\u6027<\/h1>\n<p>\u5f53\u6211\u4eec\u5728\u7a0b\u5e8f\u4e2d\u64cd\u4f5c\u6587\u4ef6\u65f6\uff0c\u53ef\u80fd\u4f1a\u4f7f\u7528\u5230\u6587\u4ef6\u7684\u4e00\u4e9b\u5e38\u89c1\u5c5e\u6027\uff0c\u6bd4\u5982\u6587\u4ef6\u7684\u5927\u5c0f\u3001\u7c7b\u578b\u3001\u4fee\u6539\u65f6\u95f4\u3001\u8bbf\u95ee\u65f6\u95f4\u4ee5\u53ca\u6743\u9650\u7b49\u7b49\u3002PHP \u4e2d\u63d0\u4f9b\u4e86\u975e\u5e38\u5168\u9762\u7684\u7528\u6765\u83b7\u53d6\u8fd9\u4e9b\u5c5e\u6027\u7684\u5185\u7f6e\u51fd\u6570\uff0c\u5982\u4e0b\u8868\u6240\u793a\u3002<\/p>\n<p><img loading="lazy" decoding="async" decoding=\"async\"  src=\"https:\/\/www.youvii.site\/wp-content\/themes\/lolimeow-lolimeowV13.13\/assets\/images\/loading.gif\" data-src=\"https:\/\/cdn.picui.cn\/vip\/2025\/10\/24\/68faeacc8509e.png\" class=\"lazy\" loading=\"lazy\" alt=\"1745379199167-fac96dc0-3719-4563-9dee-db209fa852c5.png\" \/><\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$file = 'test.txt';\nfile_exists($file) or die('\u6587\u4ef6\u4e0d\u5b58\u5728\uff0c\u7a0b\u5e8f\u9000\u51fa\uff01');\necho $file.' \u6587\u4ef6\u5927\u5c0f\u662f\uff1a'.filesize($file).' \u4e2a\u5b57\u8282&lt;br&gt;';\nif(is_readable($file)){\necho $file.' \u6587\u4ef6\u662f\u53ef\u8bfb\u7684\u3002&lt;br&gt;';\n}else{\necho $file.' \u6587\u4ef6\u662f\u4e0d\u53ef\u8bfb\u7684\u3002&lt;br&gt;';\n}\nif(is_writable($file)){\necho $file.' \u6587\u4ef6\u662f\u53ef\u5199\u7684\u3002&lt;br&gt;';\n}else{\necho $file.' \u6587\u4ef6\u662f\u4e0d\u53ef\u5199\u7684\u3002&lt;br&gt;';\n}\nif(is_executable($file)){\necho $file.' \u6587\u4ef6\u662f\u53ef\u6267\u884c\u7684\u3002&lt;br&gt;';\n}else{\necho $file.' \u6587\u4ef6\u662f\u4e0d\u53ef\u6267\u884c\u7684\u3002&lt;br&gt;';\n}\necho '\u6587\u4ef6\u7684\u521b\u5efa\u65f6\u95f4\u662f\uff1a'.date('Y-m-d H:i:s',filectime($file)).'\u3002\n&lt;br&gt;';\necho '\u6587\u4ef6\u7684\u4fee\u6539\u65f6\u95f4\u662f\uff1a'.date('Y-m-d H:i:s',filemtime($file)).'\u3002\n&lt;br&gt;';\necho '\u6587\u4ef6\u4e0a\u6b21\u7684\u8bbf\u95ee\u65f6\u95f4\u662f\uff1a'.date('Y-m-d\nH:i:s',fileatime($file)).'\u3002&lt;br&gt;';\n?&gt;<\/code><\/pre>\n<h1>PHP \u76ee\u5f55\u64cd\u4f5c<\/h1>\n<p>\u76ee\u5f55\u64cd\u4f5c<\/p>\n<p>\u65b0\u5efa\u76ee\u5f55\uff1amkdir(\u8def\u5f84\uff0c\u6743\u9650\uff0c\u9012\u5f52\u521b\u5efa)<\/p>\n<p>\u5220\u9664\u76ee\u5f55\uff1armdir()<\/p>\n<p>\u79fb\u52a8\uff08\u6539\u540d\uff09\uff1arename()<\/p>\n<p>\u83b7\u53d6\u76ee\u5f55\u5185\u5bb9\uff1a<\/p>\n<p>\/\/\u6253\u5f00\u76ee\u5f55<\/p>\n<p>\u76ee\u5f55\u53e5\u67c4 = opendir()<\/p>\n<p>\/\/\u8bfb\u53d6\u76ee\u5f55<\/p>\n<p>\u6587\u4ef6\u540d = readdir(\u76ee\u5f55\u53e5\u67c4)<\/p>\n<p>\u4f9d\u6b21\u8bfb\u53d6\u6587\u4ef6\u540d\uff0c\u540c\u65f6\u5411\u4e0b\u79fb\u52a8\u6587\u4ef6\u53e5\u67c4\u6307\u9488\uff0c\u8bfb\u53d6\u4e0d\u5230\u5219\u8fd4\u56de false<\/p>\n<p>\/\/\u5173\u95ed\u76ee\u5f55<\/p>\n<p>closedir()<\/p>\n<p>\u5f53\u524d\u76ee\u5f55. \u4e0a\u7ea7\u76ee\u5f55\u7528..<\/p>\n<p>\u9012\u5f52\u8bfb\u53d6\u76ee\u5f55\u5185\u5bb9\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n\/\/\u9012\u5f52\u904d\u5386\u76ee\u5f55\n$dirfile=\"c:\/\";\nfunction tree($dirfile){\n$dir = opendir($dirfile);\nwhile (($file = readdir($dir)) !== false)\n{\nif(is_dir(\"$dirfile{$file}\") &amp;&amp; ($file !=\".\") &amp;&amp; ($file !=\"..\")){\nif(is_readable(\"$dirfile{$file}\")){\necho \"\u76ee\u5f55 $dirfile{$file} &lt;\/br&gt;\";\ntree(\"$dirfile{$file}\");\n}else{\necho \"\u76ee\u5f55 $dirfile{$file} \u4e0d\u53ef\u8bbf\u95ee&lt;\/br&gt;\";\n}\n}\nelse{\nif( ($file !=\".\") &amp;&amp; ($file !=\"..\")){\necho \"\u6587\u4ef6 $dirfile\/{$file} &lt;\/br&gt;\";\n}\n}\n}\nclosedir($dir);\n}\ntree($dirfile);\n?&gt;<\/code><\/pre>\n<h1>\u547d\u540d\u7a7a\u95f4<\/h1>\n<p>PHP \u547d\u540d\u7a7a\u95f4\u53ef\u4ee5\u89e3\u51b3\u4ee5\u4e0b\u4e24\u7c7b\u95ee\u9898<\/p>\n<p>1.\u7528\u6237\u7f16\u5199\u7684\u4ee3\u7801\u4e0e PHP \u5185\u90e8\u7684\u7c7b\/\u51fd\u6570\/\u5e38\u91cf\u6216\u7b2c\u4e09\u65b9\u7c7b\/\u51fd\u6570\/\u5e38\u91cf\u4e4b\u95f4\u7684\u540d\u5b57\u51b2\u7a81\u3002<\/p>\n<p>2.\u4e3a\u5f88\u957f\u7684\u6807\u8bc6\u7b26\u540d\u79f0(\u901a\u5e38\u662f\u4e3a\u4e86\u7f13\u89e3\u7b2c\u4e00\u7c7b\u95ee\u9898\u800c\u5b9a\u4e49\u7684)\u521b\u5efa\u4e00\u4e2a\u522b\u540d\uff08\u6216\u7b80\u77ed\uff09\u7684\u540d\u79f0\uff0c\u4ee5\u63d0\u9ad8\u6e90\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u3002<\/p>\n<p>\u547d\u540d\u7a7a\u95f4\uff08\u53ef\u4ee5\u7406\u89e3\u4e3a\u521b\u5efa\u6587\u4ef6\u5939\uff09<\/p>\n<p>\u5b9a\u4e49\uff1a\u547d\u540d\u7a7a\u95f4 namespace\uff0c\u662f\u6307\u4eba\u4e3a\u7684\u5c06\u5185\u5b58\u8fdb\u884c\u5206\u9694\uff0c\u8ba9\u4e0d\u540c\u5185\u5b58\u533a\u57df\u7684\u540c\u540d\u7ed3\u6784\u5171\u5b58\uff0c\u4ece\u800c\u89e3\u51b3\u5728\u5927\u578b\u9879\u76ee\u4e2d\u53ef\u80fd\u51fa\u73b0\u7684\u91cd\u540d\u7ed3\u6784\u7684\u95ee\u9898<\/p>\n<p>\u8bed\u6cd5\uff1anamespace \u7a7a\u95f4\u540d<\/p>\n<p>\u4f5c\u7528\uff1a\u4e0d\u540c\u7684\u7a7a\u95f4\u53ef\u4ee5\u6709\u540c\u540d\u7684\u7ed3\u6784\uff0c\u5982\uff1a\u7c7b<\/p>\n<p>\u7a7a\u95f4\u5143\u7d20\uff1a\u51fd\u6570\uff0c\u5e38\u91cf\uff0c\u7c7b\uff0c\u4e0d\u5305\u62ec\u53d8\u91cf\uff01\uff01<\/p>\n<p>\u5b50\u7a7a\u95f4\uff08\u5b50\u6587\u4ef6\u5939\uff09<\/p>\n<p>\u5b9a\u4e49\uff1a\u547d\u540d\u7a7a\u95f4\u5185\u90e8\u518d\u5212\u5206\u4e00\u4e2a\u547d\u540d\u7a7a\u95f4\uff0c\u8ba9\u6bcf\u4e2a\u5c0f\u7a7a\u95f4\u72ec\u7acb\u8d77\u6765<\/p>\n<p>\u8bed\u6cd5:<\/p>\n<p>namespace \u7a7a\u95f4\u540d<\/p>\n<p>namespace \u7a7a\u95f4\u540d\u5b50\u7a7a\u95f4<\/p>\n<p>\u547d\u540d\u7a7a\u95f4\u8bbf\u95ee \uff08url\uff09<\/p>\n<p>\u975e\u9650\u5b9a\u540d\u79f0\u8bbf\u95ee\uff1a\u76f4\u63a5\u8bbf\u95ee\u7a7a\u95f4\u5143\u7d20\u7684\u540d\u5b57\uff08\u53ea\u8bbf\u95ee\u81ea\u5df1\u547d\u540d\u7a7a\u95f4\u7684\u5143\u7d20\uff09<\/p>\n<p>\u9650\u5b9a\u540d\u79f0\u8bbf\u95ee\uff1a\u4f7f\u7528\u81ea\u5df1\u5f53\u524d\u7684\u5b50\u7a7a\u95f4\u540d\u5b57+  + \u5143\u7d20\u540d\u5b57<\/p>\n<p>\u5b8c\u5168\u9650\u5b9a\u540d\u79f0\u8bbf\u95ee\uff1a + \u5168\u5c40\u7a7a\u95f4 +  + \u5143\u7d20\u540d\u5b57<\/p>\n<p>\u6ce8\uff1a\u4efb\u4f55\u7a7a\u95f4\u5143\u7d20\u8bbf\u95ee\uff0c\u53ea\u9488\u5bf9\u51fd\u6570\uff0c\u7c7b\uff0c\u5e38\u91cf<\/p>\n<p>\u5168\u5c40\u7a7a\u95f4\uff08C \u76d8\uff09<\/p>\n<p>\u5982\u679c\u5b9a\u4e49\u4e86\u547d\u540d\u7a7a\u95f4\uff0c\u975e\u9650\u5b9a\u540d\u79f0\u7684\u5bfb\u627e\u7cfb\u7edf\u5e38\u91cf\u7684\u65b9\u5f0f\uff1a<\/p>\n<p>\u9996\u5148\uff1a\u5728\u81ea\u5df1\u7684\u7a7a\u95f4\u5185\u627e<\/p>\n<p>\u7136\u540e\uff1a\u5982\u679c\u627e\u4e0d\u5230\u5143\u7d20<\/p>\n<p>\u7cfb\u7edf\u5e38\u91cf&#8211;&gt;\u8fdb\u5165\u5168\u5c40\u7a7a\u95f4\u5bfb\u627e<\/p>\n<p>\u7cfb\u7edf\u7c7b &#8211;&gt; \u4e0d\u4f1a\u81ea\u52a8\u8fdb\u5165\u5168\u5c40\u7a7a\u95f4\u5bfb\u627e\uff0c\u800c\u662f\u4f1a\u62a5\u9519<\/p>\n<p>\u547d\u540d\u7a7a\u95f4\u7684\u5f15\u5165<\/p>\n<p>1.\u7a7a\u95f4\u5f15\u5165\u65b9\u5f0f\uff1ause \u5173\u952e\u5b57<\/p>\n<ol>\n<li>\n<p>\u5f15\u5165\u7c7b\uff1ause \u7a7a\u95f4\u540d\u7c7b\u540d<\/p>\n<\/li>\n<li>\n<p>\u5f15\u5165\u51fd\u6570\uff1ause function \u7a7a\u95f4\u540d\u51fd\u6570\u540d<\/p>\n<\/li>\n<li>\n<p>\u5f15\u5165\u5e38\u91cf\uff1ause const \u7a7a\u95f4\u540d\u5e38\u91cf\u540d<\/p>\n<\/li>\n<\/ol>\n<p>2.\u5f53\u5f15\u5165\u5143\u7d20\u65f6\u91cd\u540d\uff0c\u901a\u8fc7 as \u6765\u8d77\u522b\u540d<\/p>\n<p>use \u7a7a\u95f4\u540d\u7c7b\u540d as \u522b\u540d<\/p>\n<p>3.\u5f15\u5165\u591a\u4e2a\u5143\u7d20<\/p>\n<p>use \u7a7a\u95f4\u540d{<\/p>\n<p>\u7c7b\u540d\uff0c<\/p>\n<p>function \u51fd\u6570\u540d\uff0c<\/p>\n<p>const \u5e38\u91cf<\/p>\n<p>}<\/p>\n<ol start=\"4\">\n<li>\u5f15\u5165\u7a7a\u95f4<\/li>\n<\/ol>\n<p>use \u7a7a\u95f4\u540d<\/p>\n<h1>\u6b63\u5219\u8868\u8fbe\u5f0f<\/h1>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7b80\u4ecb<\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u7528\u4e8e\u63cf\u8ff0\u5b57\u7b26\u6392\u5217\u548c\u5339\u914d\u6a21\u5f0f\u7684\u4e00\u79cd\u8bed\u6cd5\u89c4\u5219\u3002\u5b83\u4e3b\u8981\u7528\u4e8e\u5b57\u7b26\u4e32\u7684\u6a21\u5f0f\u5206\u5272\u3001\u5339\u914d\u3001\u67e5\u627e\u53ca\u66ff\u6362\u64cd\u4f5c\u3002\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u4eec\u524d\u9762\u6240\u7528\u8fc7\u7684\u7cbe\u786e\uff08\u6587\u672c\uff09\u5339\u914d\u4e5f\u662f\u4e00\u79cd\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/p>\n<p>\u5728 PHP \u4e2d\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u4e00\u822c\u662f\u7531\u6b63\u89c4\u5b57\u7b26\u548c\u4e00\u4e9b\u7279\u6b8a\u5b57\u7b26\uff08\u7c7b\u4f3c\u4e8e\u901a\u914d\u7b26\uff09\u8054\u5408\u6784\u6210\u7684\u4e00\u4e2a\u6587\u672c\u6a21\u5f0f\u7684\u7a0b\u5e8f\u6027\u63cf\u8ff0<\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u8f83\u91cd\u8981\u548c\u8f83\u6709\u7528\u7684\u89d2\u8272\u662f\u9a8c\u8bc1\u7528\u6237\u6570\u636e\u7684\u6709\u6548\u6027\u68c0\u67e5\u3002PHP \u4e2d\uff0c\u6b63\u5219<\/p>\n<p>\u8868\u8fbe\u5f0f\u6709\u4e09\u4e2a\u4f5c\u7528\uff1a<\/p>\n<p>\u5339\u914d\uff0c\u4e5f\u5e38\u5e38\u7528\u4e8e\u4ece\u5b57\u7b26\u4e32\u4e2d\u6790\u53d6\u4fe1\u606f\u3002<\/p>\n<p>\u7528\u65b0\u6587\u672c\u4ee3\u66ff\u5339\u914d\u6587\u672c\u3002<\/p>\n<p>\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u4e00\u7ec4\u66f4\u5c0f\u7684\u4fe1\u606f\u5757\u3002<\/p>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u57fa\u672c\u8bed\u6cd5<\/p>\n<p>PCRE \u5e93\u51fd\u6570\u4e2d\uff0c\u6b63\u5219\u5339\u914d\u6a21\u5f0f\u4f7f\u7528\u5206\u9694\u7b26\u4e0e\u5143\u5b57\u7b26\u7ec4\u6210\uff0c\u5206\u9694\u7b26\u53ef\u4ee5\u662f\u975e\u6570\u5b57\u3001\u975e\u53cd\u659c\u7ebf\u3001\u975e\u7a7a\u683c\u7684\u4efb\u610f\u5b57\u7b26\u3002\u7ecf\u5e38\u4f7f\u7528\u7684\u5206\u9694\u7b26\u662f\u6b63\u659c\u7ebf(\/)\u3001hash \u7b26\u53f7(#) \u4ee5\u53ca\u53d6\u53cd\u7b26\u53f7(~)\u5143\u5b57\u7b26\u662f\u7528\u4e8e\u6784\u9020\u89c4\u5219\u8868\u8fbe\u5f0f\u7684\u5177\u6709\u7279\u6b8a\u542b\u4e49\u7684\u5b57\u7b26\u3002\u5982\u679c\u8981\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u5305\u542b\u5143\u5b57\u7b26\u672c\u8eab\uff0c\u5fc5\u987b\u5728\u5176\u524d\u52a0\u4e0a\u201d\u201d\u8fdb\u884c\u8f6c\u4e49<\/p>\n<p>\u5f53\u7136\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u8868\u683c\u5f62\u5f0f\u7684PHP\u6b63\u5219\u8868\u8fbe\u5f0f\u5143\u5b57\u7b26\u53ca\u5176\u8bf4\u660e\uff1a<\/p>\n<div class=\"table-responsive\"><table class=\"table\" >\n<thead>\n<tr>\n<th>\u5143\u5b57\u7b26<\/th>\n<th>\u8bf4\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>.<\/code><\/td>\n<td>\u5339\u914d\u9664\u4e86\u6362\u884c\u7b26\u4e4b\u5916\u7684\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>^<\/code><\/td>\n<td>\u5339\u914d\u5b57\u7b26\u4e32\u5f00\u59cb\u7684\u4f4d\u7f6e\u3002\u5982\u679c\u4f7f\u7528\u4e86<code>m<\/code>\u4fee\u9970\u7b26\uff08\u591a\u884c\u6a21\u5f0f\uff09\uff0c\u5b83\u4e5f\u5339\u914d\u6bcf\u884c\u7684\u5f00\u5934\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>$<\/code><\/td>\n<td>\u5339\u914d\u5b57\u7b26\u4e32\u7ed3\u675f\u7684\u4f4d\u7f6e\u3002\u82e5\u4f7f\u7528<code>m<\/code>\u4fee\u9970\u7b26\uff0c\u5219\u4e5f\u5339\u914d\u6bcf\u884c\u7684\u672b\u5c3e\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>*<\/code><\/td>\n<td>\u96f6\u6b21\u6216\u591a\u6b21\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>+<\/code><\/td>\n<td>\u4e00\u6b21\u6216\u591a\u6b21\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>?<\/code><\/td>\n<td>\u96f6\u6b21\u6216\u4e00\u6b21\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u3002\u5f53\u7528\u4e8e\u91cf\u8bcd\u540e\u65f6\uff0c\u8868\u793a\u975e\u8d2a\u5a6a\u6a21\u5f0f\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>{n}<\/code><\/td>\n<td>\u6070\u597d n \u6b21\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>{n,}<\/code><\/td>\n<td>\u81f3\u5c11 n \u6b21\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>{n,m}<\/code><\/td>\n<td>\u5339\u914d\u524d\u9762\u7684\u5143\u7d20\u81f3\u5c11 n \u6b21\u4f46\u4e0d\u8d85\u8fc7 m \u6b21\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>[abc]<\/code><\/td>\n<td>\u5b57\u7b26\u96c6\uff0c\u5339\u914d\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>[^abc]<\/code><\/td>\n<td>\u53cd\u5411\u5b57\u7b26\u96c6\uff0c\u5339\u914d\u4e0d\u5728\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u610f\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>|<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>( )<\/code><\/td>\n<td>\u5206\u7ec4\u6355\u83b7\uff0c\u5c06\u62ec\u53f7\u5185\u7684\u5185\u5bb9\u4f5c\u4e3a\u4e00\u4e2a\u6574\u4f53\u5904\u7406\uff0c\u5e76\u53ef\u7528\u4e8e\u540e\u9762\u5f15\u7528\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>d<\/code><\/td>\n<td>\u7b49\u540c\u4e8e <code>[0-9]<\/code>\uff0c\u5339\u914d\u4efb\u4f55\u4e00\u4e2a\u6570\u5b57\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>D<\/code><\/td>\n<td>\u7b49\u540c\u4e8e <code>[^0-9]<\/code>\uff0c\u5339\u914d\u4efb\u4f55\u975e\u6570\u5b57\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>w<\/code><\/td>\n<td>\u7b49\u540c\u4e8e <code>[a-zA-Z0-9_]<\/code>\uff0c\u5339\u914d\u5b57\u6bcd\u3001\u6570\u5b57\u53ca\u4e0b\u5212\u7ebf\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>W<\/code><\/td>\n<td>\u7b49\u540c\u4e8e <code>[^a-zA-Z0-9_]<\/code>\uff0c\u5339\u914d\u9664\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u5916\u7684\u6240\u6709\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>s<\/code><\/td>\n<td>\u5339\u914d\u7a7a\u767d\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u683c\u3001\u5236\u8868\u7b26\u3001\u6362\u9875\u7b26\u7b49\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>S<\/code><\/td>\n<td>\u5339\u914d\u975e\u7a7a\u767d\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>b<\/code><\/td>\n<td>\u5355\u8bcd\u8fb9\u754c\uff0c\u4f4d\u4e8e<code>w<\/code>\u4e0e<code>W<\/code>\u4e4b\u95f4\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>B<\/code><\/td>\n<td>\u975e\u5355\u8bcd\u8fb9\u754c\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>1<\/code>, <code>2<\/code>, &#8230;<\/td>\n<td>\u5f15\u7528\u524d\u9762\u7b2c1\u4e2a\u3001\u7b2c2\u4e2a&#8230;\u5206\u7ec4\u7684\u5185\u5bb9\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>\\<\/code><\/td>\n<td>\u8f6c\u4e49\u5b57\u7b26\uff0c\u7528\u6765\u8f6c\u4e49\u7279\u6b8a\u5b57\u7b26\u4f7f\u5176\u5931\u53bb\u7279\u6b8a\u610f\u4e49\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<h3>\u8fb9\u754c\u9650\u5236<\/h3>\n<p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u5bf9\u5339\u914d\u8303\u56f4\u8fdb\u884c\u9650\u5b9a\uff0c\u4ee5\u83b7\u5f97\u66f4\u51c6\u786e\u7684\u5339\u914d\u7ed3\u679c\u3002\u201c^\u201d\u548c<\/p>\n<p>\u201c$\u201d\u5206\u522b\u6307\u5b9a\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u548c\u7ed3\u675f\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5728\u5b57\u7b26\u4e32\u201cTom and Jerry chased each other in the house until tom\u2019s uncelcome in\u201d\u4e2d<\/p>\n<p>\u5143\u5b57\u7b26\u201c^\u201d \u7f6e\u4e8e\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u786e\u4fdd\u6a21\u5f0f\u5339\u914d\u51fa\u73b0\u5728\u5b57\u7b26\u4e32\u9996\u7aef\uff1b<\/p>\n<p>^Tom<\/p>\n<p>\u5143\u5b57\u7b26\u201c$\u201d \u7f6e\u4e8e\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\uff0c\u786e\u4fdd\u6a21\u5f0f\u5339\u914d\u51fa\u73b0\u5b57\u7b26\u4e32\u5c3e\u7aef\u3002<\/p>\n<p>in$<\/p>\n<p>\u5982\u679c\u4e0d\u52a0\u8fb9\u754c\u9650\u5236\u5143\u5b57\u7b26\uff0c\u5c06\u83b7\u5f97\u66f4\u591a\u7684\u5339\u914d\u7ed3\u679c\u3002<\/p>\n<p>^Tom$\u7cbe\u786e\u5339\u914d Tom \u6a21\u7cca\u5339\u914d<\/p>\n<h3>\u91cd\u590d\u5339\u914d<\/h3>\n<p>\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u6709\u4e00\u4e9b\u7528\u4e8e\u91cd\u590d\u5339\u914d\u67d0\u4e9b\u539f\u5b50\u7684\u5143\u5b57\u7b26\uff1a\u201c?\u201d\u3001\u201c*\u201d\u3001\u201c+\u201d\u3002<\/p>\n<p>\u4ed6\u4eec\u4e3b\u8981\u7684\u4e0d\u540c\u662f\u91cd\u590d\u5339\u914d\u7684\u6b21\u6570\u4e0d\u540c\u3002<\/p>\n<p>\u5143\u5b57\u7b26\u201c?\u201d:\u8868\u793a 0 \u6b21\u6216 1 \u6b21\u5339\u914d\u7d27\u63a5\u5728\u5176\u524d\u7684\u539f\u5b50\u3002<\/p>\n<p>\u4f8b\u5982\uff1acolou?r \u5339\u914d\u201ccolour\u201d\u6216\u201ccolor\u201d\u3002<\/p>\n<p>\u5143\u5b57\u7b26\u201c*\u201d:\u8868\u793a 0 \u6b21\u30011 \u6b21\u6216\u591a\u6b21\u5339\u914d\u7d27\u63a5\u5728\u5176\u524d\u7684\u539f\u5b50\u3002<\/p>\n<p>\u4f8b\u5982\uff1azo*\u53ef\u4ee5\u5339\u914d z\u3001zoo<\/p>\n<p>&lt;[A-Za-z][A-Za-z0-9]*&gt;\u53ef\u4ee5\u5339\u914d\u201c<P>\u201d\u3001\u201c<hl>\u201d\u6216\u201c<Body>\u201d\u7b49 HTML \u6807\u7b7e\uff0c\u5e76\u4e14\u4e0d\u4e25\u683c\u7684\u63a7\u5236\u5927\u5c0f\u5199\u3002<\/p>\n<p>\u5143\u5b57\u7b26\u201c+\u201d:\u8868\u793a 1 \u6b21\u6216\u591a\u6b21\u5339\u914d\u7d27\u63a5\u5728\u5176\u524d\u7684\u539f\u5b50\u3002<\/p>\n<p>\u4f8b\u5982\uff1ago+gle \u5339\u914d\u201cgogle\u201d\u3001\u201cgoogle\u201d\u6216\u201cgooogle\u201d\u7b49\u4e2d\u95f4\u542b\u6709\u591a\u4e2a o \u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4f8b\u5b50\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff0c\u5339\u914d\u8868\u8fbe\u5f0f\u662f 0?[ xX][0-9a-fA-F]+,\u53ef\u4ee5\u5339\u914d\u201c0x9B3C\u201d\u6216\u8005\u201cX800\u201d\u7b49\u3002<\/p>\n<p>\u5143\u5b57\u7b26 \u201c.\u201d<\/p>\n<p>\u5143 \u5b57 \u7b26 \u201c . \u201d \u5339 \u914d \u9664 \u6362 \u884c \u7b26 \u5916 \u4efb \u4f55 \u4e00 \u4e2a \u5b57 \u7b26 \uff0c \u76f8 \u5f53 \u4e8e [^n](Unix \u7cfb \u7edf ) \u6216[^rn](windows \u7cfb\u7edf)\u3002<\/p>\n<p>\u4f8b\u5982\uff1apr.y \u53ef\u4ee5\u5339\u914d\u7684\u5b57\u7b26\u4e32\u201cprey\u201d\u3001\u201cpray\u201d\u6216\u201cpr%y\u201d\u7b49\u3002<\/p>\n<p>\u901a\u5e38\u53ef\u4ee5\u4f7f\u7528\u201c.*\u201d\u7ec4\u5408\u6765\u5339\u914d\u9664\u6362\u884c\u7b26\u5916\u7684\u4efb\u4f55\u5b57\u7b26\u3002\u5728\u4e00\u4e9b\u4e66\u7c4d\u4e2d\u4e5f\u79f0\u5176\u4e3a<\/p>\n<p>\u201c\u5168\u5339\u914d\u7b26\u201d \u6216 \u201c\u5355\u542b\u5339\u914d\u7b26\u201d\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<p>^a.*z$\u8868\u793a\u53ef\u4ee5\u5339\u914d\u5b57\u6bcd\u201ca\u201d\u5f00\u5934\uff0c\u5b57\u6bcd\u201cz\u201d\u7ed3\u675f\u7684\u4efb\u610f\u4e0d\u5305\u62ec\u6362\u884c\u7b26\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>.+\u4e5f\u53ef\u4ee5\u5b8c\u6210\u7c7b\u4f3c\u7684\u5339\u914d\u529f\u80fd\u6240\u4e0d\u540c\u7684\u662f\u5176\u81f3\u5c11\u5339\u914d\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>^a.+z$\u5c06\u4e0d\u5339\u914d\u5b57\u7b26\u4e32\u201caz\u201d\u3002<\/p>\n<p>\u91cd\u590d\u5339\u914d<\/p>\n<p>\u5143\u5b57\u7b26\u201c{}\u201d\u51c6\u786e\u5730\u6307\u5b9a\u539f\u5b50\u91cd\u590d\u7684\u6b21\u6570\uff0c\u6307\u5b9a\u6240\u5339\u914d\u7684\u539f\u5b50\u51fa\u73b0\u7684\u6b21\u6570\u3002<\/p>\n<p>\u201c{m}\u201d\u8868\u793a\u5176\u524d\u539f\u5b50\u6070\u597d\u51fa\u73b0 m \u6b21\uff1b<\/p>\n<p>\u201c{m\uff0cn}\u201d\u8868\u793a\u5176\u524d\u539f\u5b50\u81f3\u5c11\u51fa\u73b0 m \u6b21\uff0c\u81f3\u591a\u51fa\u73b0 n \u6b21\uff1b<\/p>\n<p>\u201c{m\uff0c}\u201d\u8868\u793a\u5176\u524d\u539f\u5b50\u51fa\u73b0\u4e0d\u5c11\u4e8e m \u6b21\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<p>zo{1,3}m \u53ea\u80fd\u5339\u914d\u5b57\u7b26\u4e32\u201czom\u201d\u3001\u201czoom\u201d\u3001\u6216\u201czooom\u201d\u3002<\/p>\n<p>zo{3}m \u53ea\u80fd\u5339\u914d\u5b57\u7b26\u4e32\u201czooom\u201d<\/p>\n<p>zo{3\uff0c}m \u53ef\u4ee5\u5339\u914d\u4ee5 \u201cz\u201d \u5f00\u5934\uff0c\u201cm\u201d\u7ed3\u675f\uff0c\u4e2d\u95f4\u81f3\u5c11\u4e3a 3 \u4e2a\u201co\u201d\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>bo{0,1}u \u53ef\u4ee5\u5339\u914d\u5b57\u7b26\u4e32\u201cbought a butter\u201d \u4e2d\u7684\u201cbou\u201d\u548c\u201cbu\u201d,\u7b49\u4ef7\u4e8ebo?u\u3002<\/p>\n<p>\u539f\u5b50\u8868 \uff0d\u65b9\u62ec\u53f7\u8868\u8fbe\u5f0f<\/p>\n<p>\u539f\u5b50\u8868\u201d[]\u201d\u4e2d\u5b58\u653e\u4e00\u7ec4\u539f\u5b50\uff0c\u5f7c\u6b64\u5730\u4f4d\u5e73\u7b49\uff0c\u4e14\u4ec5\u5339\u914d\u5176\u4e2d\u7684\u4e00\u4e2a\u539f\u5b50\u3002\u5982\u679c\u60f3\u5339\u914d\u4e00\u4e2a \u201da\u201d \u6216 \u201de\u201d \u4f7f\u7528 [ae]\u3002<\/p>\n<p>\u4f8b\u5982: Pr[ae]y \u5339\u914d \u201dPray\u201d \u6216\u8005 \u201dPrey \u201d\u3002<\/p>\n<p>\u539f\u5b50\u8868 \u201d[^]\u201d \u6216\u8005\u79f0\u4e3a\u6392\u9664\u539f\u5b50\u8868\uff0c\u5339\u914d\u9664\u8868\u5185\u539f\u5b50\u5916\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>\u4f8b\u5982\uff1ap[^u]\u5339\u914d\u201cpart\u201d\u4e2d\u7684\u201cpa\u201d\uff0c\u4f46\u65e0\u6cd5\u5339\u914d\u201ccomputer\u201d\u4e2d\u7684\u201cpu\u201d\u56e0\u4e3a\u201cu\u201d\u5728\u5339\u914d\u4e2d\u88ab\u6392\u9664\u3002<\/p>\n<p>\u539f\u5b50\u8868\u201c[-]\u201d\u7528\u4e8e\u8fde\u63a5\u4e00\u7ec4\u6309 ASCII \u7801\u987a\u5e8f\u6392\u5217\u7684\u539f\u5b50\uff0c\u7b80\u5316\u4e66\u5199\u3002<\/p>\n<p>\u4f8b\u5982\uff1ax[0123456789]\u53ef\u4ee5\u5199\u6210 x[0-9],\u7528\u6765\u5339\u914d\u4e00\u4e2a\u7531 \u201cx\u201d \u5b57\u6bcd\u4e0e\u4e00\u4e2a\u6570\u5b57\u7ec4\u6210\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<p>[a-zA-Z]\u5339\u914d\u6240\u6709\u5927\u5c0f\u5199\u5b57\u6bcd<\/p>\n<p>^[a-z][0-9]$\u5339\u914d\u6bd4\u5982\u201cz2\u201d\u3001 \u201ct6\u201d \u3001\u201cg7\u201d<\/p>\n<p>0[xX][0-9a-fA-F]\u5339\u914d\u4e00\u4e2a\u7b80\u5355\u7684\u5341\u516d\u8fdb\u5236\u6570\u5b57\uff0c\u5982\u201c0x9\u201d\u3002<\/p>\n<p>[^0-9a-zA-Z_]\u5339\u914d\u9664\u82f1\u6587\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u4ee5\u5916\u4efb\u4f55\u4e00\u4e2a\u5b57\u7b26\uff0c\u5176\u7b49\u4ef7\u4e8eW\u3002<\/p>\n<p>\u6a21\u5f0f\u9009\u62e9\u7b26<\/p>\n<p>\u5143\u5b57\u7b26\u201c|\u201d\u53c8\u79f0\u6a21\u5f0f\u9009\u62e9\u7b26\u3002\u5728\u6b63\u5219\u8868\u8fbe\u5f0f\u4e2d\u5339\u914d\u4e24\u4e2a\u6216\u66f4\u591a\u7684\u9009\u62e9\u4e4b\u4e00\u3002<\/p>\n<p>\u4f8b\u5982\uff1a\u5728\u5b57\u7b26\u4e32\u201cThere are many apples and pears.\u201d\u4e2d\uff0capple|pear \u5728\u7b2c\u4e00\u6b21\u8fd0\u884c<\/p>\n<p>\u65f6\u5339\u914d\u201capple\u201d\uff1b\u518d\u6b21\u8fd0\u884c\u65f6\u5339\u914d\u201c pear\u201d\u3002\u4e5f\u53ef\u4ee5\u7ee7\u7eed\u589e\u52a0\u9009\u9879\uff0c\u5982\uff1a<\/p>\n<p>apple|pear|banana|lemon<\/p>\n<p>POSIX \u98ce\u683c\u9884\u5b9a\u4e49\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5b57\u7b26\u7c7b\uff1a<\/p>\n<p>[[:alnum:]] \u5b57\u6bcd\u548c\u6570\u5b57\u5b57\u7b26<\/p>\n<p>[[:alpha:]] \u5927\u5c0f\u5199\u5b57\u6bcd<\/p>\n<p>[[:lower:]] \u5c0f\u5199\u5b57\u6bcd<\/p>\n<p>[[:upper:]] \u5927\u5199\u5b57\u6bcd<\/p>\n<p>[[:digit:]] \u6570\u5b57 0-9<\/p>\n<p>[[:xdigit:]] \u5341\u516d\u8fdb\u5236\u6570\u5b57<\/p>\n<p>[[:punct:]] \u6807\u70b9\u7b26\u53f7\uff0c\u5305\u62ec\u4e0a\u6863\u952e!@<\/p>\n<p>[[:blank:]] TAB \u5236\u8868\u7b26\u548c\u7a7a\u683c<\/p>\n<p>[[:space:]] \u4efb\u4f55\u7a7a\u767d\u5b57\u7b26,\u6362\u884c,\u56de\u8f66\u7b26<\/p>\n<p>[[:cntrl:]] \u63a7\u5236\u5b57\u7b26\uff08TAB\uff0c\u9000\u683c\uff09<\/p>\n<p>\u6a21\u5f0f\u5355\u5143<\/p>\n<p>\u5143\u5b57\u7b26\u201c\uff08\uff09\u201d\u5c06\u5176\u4e2d\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u53d8\u4e3a\u539f\u5b50\uff08\u6216\u79f0\u6a21\u5f0f\u5355\u5143\uff09\u4f7f\u7528\u3002\u4e0e\u6570\u5b66\u8868\u8fbe\u5f0f\u4e2d\u7684\u62ec\u53f7\u7c7b\u4f3c\uff0c\u201c\uff08\uff09\u201d\u53ef\u4ee5\u505a\u4e00\u4e2a\u5355\u5143\u88ab\u5355\u72ec\u4f7f\u7528\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<p>(Dog)+\u5339\u914d\u7684\u201cDog\u201d\u3001\u201cDogDog\u201d\u3001\u201cDogDogDog\u201d\u2026\u2026..,\u56e0\u4e3a\u7d27\u63a5\u7740\u201c+\u201d<\/p>\n<p>\u524d\u7684\u539f\u5b50\u662f\u5143\u5b57\u7b26\u201c\uff08\uff09\u201d\u62ec\u8d77\u6765\u7684\u5b57\u7b26\u4e32\u201cDog\u201d\u3002<\/p>\n<p>You (very)+ old \u5339\u914d\u201cYou very old\u201d\u3001 \u201cYou very very old\u201d<\/p>\n<p>Hello (world|earth)\u5339\u914d\u201cHello world\u201d\u3001\u201cHello earth\u201d<\/p>\n<p>\u4e00\u4e2a\u6a21\u5f0f\u5355\u5143\u4e2d\u7684\u8868\u8fbe\u5f0f\u5c06\u88ab\u4f18\u5148\u5339\u914d\u6216\u8fd0\u7b97<\/p>\n<h3>\u7279\u6b8a\u5b57\u7b26<\/h3>\n<p>\u6240\u8c13\u7279\u6b8a\u5b57\u7b26\uff0c\u5c31\u662f\u4e00\u4e9b\u6709\u7279\u6b8a\u542b\u4e49\u7684\u5b57\u7b26\uff0c\u5982\u4e0a\u9762\u8bf4\u7684\u201d<em>.txt\u201d\u4e2d\u7684<\/em>\uff0c\u7b80\u5355\u7684\u8bf4\u5c31\u662f\u8868\u793a\u4efb\u4f55\u5b57\u7b26\u4e32\u7684\u610f\u601d\u3002\u5982\u679c\u8981\u67e5\u627e\u6587\u4ef6\u540d\u4e2d\u6709\uff0a\u7684\u6587\u4ef6\uff0c\u5219\u9700\u8981\u5bf9\uff0a\u8fdb\u884c\u8f6c\u4e49\uff0c\u5373\u5728\u5176\u524d\u52a0\u4e00\u4e2a\u3002ls *.txt\u3002\u6b63\u5219\u8868\u8fbe\u5f0f\u6709\u4ee5\u4e0b\u7279\u6b8a\u5b57\u7b26\u3002<\/p>\n<p><img loading="lazy" decoding="async" decoding=\"async\"  src=\"https:\/\/www.youvii.site\/wp-content\/themes\/lolimeow-lolimeowV13.13\/assets\/images\/loading.gif\" data-src=\"https:\/\/cdn.picui.cn\/vip\/2025\/10\/24\/68faeacf418c2.png\" class=\"lazy\" loading=\"lazy\" alt=\"1745379563949-c697f8f5-9022-44f1-b380-660a56571803.png\" \/><\/p>\n<p>\u6a21\u5f0f\u5339\u914d\u7684\u987a\u5e8f<\/p>\n<p>\u5728\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u5339\u914d\u7684\u987a\u5e8f\u3002\u901a\u5e38\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u6309\u7167\u7531\u5de6\u81f3\u53f3\u7684<\/p>\n<p>\u987a\u5e8f\u4f9d\u6b21\u5339\u914d\u3002<\/p>\n<p>\u6a21\u5f0f\u5339\u914d\u7684\u987a\u5e8f\uff08\u4ece\u9ad8\u5230\u4f4e\uff09<\/p>\n<p>\u987a\u5e8f \u5143\u5b57\u7b26 \u8bf4\u660e<\/p>\n<p>1 \uff08\uff09 \u6a21\u5f0f\u5355\u5143<\/p>\n<p>2 \uff1f* +{} \u91cd\u590d\u5339\u914d<\/p>\n<p>3 ^$ \u8fb9\u754c\u9650\u5236<\/p>\n<p>4 | \u6a21\u5f0f\u9009\u62e9<\/p>\n<h3>\u5143\u5b57\u7b26\u8868<\/h3>\n<div class=\"table-responsive\"><table class=\"table\" >\n<thead>\n<tr>\n<th>\u5b57\u7b26<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><\/td>\n<td>\u5c06\u4e0b\u4e00\u4e2a\u5b57\u7b26\u6807\u8bb0\u4e3a\u7279\u6b8a\u5b57\u7b26\u3001\u539f\u4e49\u5b57\u7b26\u3001\u5411\u540e\u5f15\u7528\u6216\u516b\u8fdb\u5236\u8f6c\u4e49\u7b26\u3002\u4f8b\u5982\uff0c<code>n<\/code> \u5339\u914d &quot;n&quot;\uff1b<code>n<\/code> \u5339\u914d\u6362\u884c\u7b26\uff1b<code>\\<\/code> \u5339\u914d <code><\/code>\uff1b<code>(<\/code> \u5339\u914d <code>(<\/code>\u3002<\/td>\n<\/tr>\n<tr>\n<td>^<\/td>\n<td>\u5339\u914d\u8f93\u5165\u5b57\u7b26\u4e32\u7684\u5f00\u59cb\u4f4d\u7f6e\u3002\u5982\u679c\u8bbe\u7f6e\u4e86 RegExp \u5bf9\u8c61\u7684 Multiline \u5c5e\u6027\uff0c<code>^<\/code> \u4e5f\u5339\u914d <code>n<\/code> \u6216 <code>r<\/code> \u4e4b\u540e\u7684\u4f4d\u7f6e\u3002<\/td>\n<\/tr>\n<tr>\n<td>$<\/td>\n<td>\u5339\u914d\u8f93\u5165\u5b57\u7b26\u4e32\u7684\u7ed3\u675f\u4f4d\u7f6e\u3002\u5982\u679c\u8bbe\u7f6e\u4e86 RegExp \u5bf9\u8c61\u7684 Multiline \u5c5e\u6027\uff0c<code>$<\/code> \u4e5f\u5339\u914d <code>n<\/code> \u6216 <code>r<\/code> \u4e4b\u524d\u7684\u4f4d\u7f6e\u3002<\/td>\n<\/tr>\n<tr>\n<td>*<\/td>\n<td>\u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\u96f6\u6b21\u6216\u591a\u6b21\u3002\u7b49\u4ef7\u4e8e <code>{0,}<\/code>\u3002\u4f8b\u5982\uff0c<code>zo*<\/code> \u53ef\u4ee5\u5339\u914d &quot;z&quot; \u4ee5\u53ca &quot;zoo&quot;\u3002<\/td>\n<\/tr>\n<tr>\n<td>+<\/td>\n<td>\u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\u4e00\u6b21\u6216\u591a\u6b21\u3002\u7b49\u4ef7\u4e8e <code>{1,}<\/code>\u3002\u4f8b\u5982\uff0c<code>zo+<\/code> \u53ef\u4ee5\u5339\u914d &quot;zo&quot; \u4ee5\u53ca &quot;zoo&quot;\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &quot;z&quot;\u3002<\/td>\n<\/tr>\n<tr>\n<td>?<\/td>\n<td>\u5339\u914d\u524d\u9762\u7684\u5b50\u8868\u8fbe\u5f0f\u96f6\u6b21\u6216\u4e00\u6b21\u3002\u7b49\u4ef7\u4e8e <code>{0,1}<\/code>\u3002\u4f8b\u5982\uff0c<code>do(es)?<\/code> \u53ef\u4ee5\u5339\u914d &quot;do&quot; \u6216 &quot;does&quot; \u4e2d\u7684 &quot;do&quot;\u3002<\/td>\n<\/tr>\n<tr>\n<td>{n}<\/td>\n<td>n \u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u3002\u5339\u914d\u786e\u5b9a\u7684 n \u6b21\u3002\u4f8b\u5982\uff0c<code>o{2}<\/code> \u80fd\u5339\u914d &quot;food&quot; \u4e2d\u7684\u4e24\u4e2a o\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &quot;Bob&quot; \u4e2d\u7684 o\u3002<\/td>\n<\/tr>\n<tr>\n<td>{n,}<\/td>\n<td>n \u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\u3002\u81f3\u5c11\u5339\u914d n \u6b21\u3002\u4f8b\u5982\uff0c<code>o{2,}<\/code> \u4e0d\u80fd\u5339\u914d &quot;Bob&quot; \u4e2d\u7684 o\uff0c\u4f46\u80fd\u5339\u914d &quot;foooood&quot; \u4e2d\u7684\u6240\u6709 o\u3002<code>o{1,}<\/code> \u7b49\u4ef7\u4e8e <code>o+<\/code>\uff1b<code>o{0,}<\/code> \u5219\u7b49\u4ef7\u4e8e <code>o*<\/code>\u3002<\/td>\n<\/tr>\n<tr>\n<td>{n,m}<\/td>\n<td>m \u548c n \u5747\u4e3a\u975e\u8d1f\u6574\u6570\uff0c\u5176\u4e2d n &lt;= m\u3002\u6700\u5c11\u5339\u914d n \u6b21\u4e14\u6700\u591a\u5339\u914d m \u6b21\u3002\u4f8b\u5982\uff0c<code>o{1,3}<\/code> \u5c06\u5339\u914d &quot;fooooood&quot; \u4e2d\u7684\u524d\u4e09\u4e2a o\u3002<code>o{0,1}<\/code> \u7b49\u4ef7\u4e8e <code>o?<\/code>\u3002<\/td>\n<\/tr>\n<tr>\n<td>?\uff08\u8ddf\u968f\u5728\u5176\u4ed6\u9650\u5236\u7b26\u540e\uff09<\/td>\n<td>\u5f53\u8be5\u5b57\u7b26\u7d27\u8ddf\u5728\u4efb\u4f55\u4e00\u4e2a\u5176\u4ed6\u9650\u5236\u7b26 (<code>*<\/code>, <code>+<\/code>, <code>?<\/code>, <code>{n}<\/code>, <code>{n,}<\/code>, <code>{n,m}<\/code>) \u540e\u9762\u65f6\uff0c\u5339\u914d\u6a21\u5f0f\u662f\u975e\u8d2a\u5a6a\u7684\u3002\u975e\u8d2a\u5a6a\u6a21\u5f0f\u5c3d\u53ef\u80fd\u5c11\u5730\u5339\u914d\u6240\u641c\u7d22\u7684\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u5b57\u7b26\u4e32 &quot;oooo&quot;\uff0c<code>o+?<\/code> \u5c06\u5339\u914d\u5355\u4e2a &quot;o&quot;\uff0c\u800c <code>o+<\/code> \u5c06\u5339\u914d\u6240\u6709 &quot;o&quot;\u3002<\/td>\n<\/tr>\n<tr>\n<td>.<\/td>\n<td>\u5339\u914d\u9664 &quot;n&quot; \u4e4b\u5916\u7684\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\u3002\u8981\u5339\u914d\u5305\u62ec &#8216;n&#8217; \u5728\u5185\u7684\u4efb\u4f55\u5b57\u7b26\uff0c\u8bf7\u4f7f\u7528 <code>[.n]<\/code> \u7684\u6a21\u5f0f\u3002<\/td>\n<\/tr>\n<tr>\n<td>(pattern)<\/td>\n<td>\u5339\u914d pattern \u5e76\u83b7\u53d6\u8fd9\u4e00\u5339\u914d\u3002\u6240\u83b7\u53d6\u7684\u5339\u914d\u53ef\u4ee5\u4ece\u4ea7\u751f\u7684 Matches \u96c6\u5408\u5f97\u5230\uff0c\u5728 VBScript \u4e2d\u4f7f\u7528 SubMatches \u96c6\u5408\uff0c\u5728 JScript \u4e2d\u5219\u4f7f\u7528 <code>$0\u2026$9<\/code> \u5c5e\u6027\u3002\u8981\u5339\u914d\u5706\u62ec\u53f7\u5b57\u7b26\uff0c\u8bf7\u4f7f\u7528 <code>''<\/code> \u6216 <code>'[]'<\/code>\u3002<\/td>\n<\/tr>\n<tr>\n<td>(?:pattern)<\/td>\n<td>\u5339\u914d pattern \u4f46\u4e0d\u83b7\u53d6\u5339\u914d\u7ed3\u679c\uff0c\u5373\u8fd9\u662f\u4e00\u4e2a\u975e\u6355\u83b7\u5339\u914d\uff0c\u4e0d\u8fdb\u884c\u5b58\u50a8\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002\u8fd9\u5728\u4f7f\u7528 \u201c\u6216\u201d \u5b57\u7b26 (`<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<div class=\"table-responsive\"><table class=\"table\" >\n<thead>\n<tr>\n<th>\u6b63\u5219\u8868\u8fbe\u5f0f<\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u793a\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>(?=pattern)<\/code><\/td>\n<td>\u6b63\u5411\u9884\u67e5\u3002\u5728\u4efb\u4f55\u5339\u914d<code>pattern<\/code>\u7684\u5b57\u7b26\u4e32\u5f00\u59cb\u5904\u5339\u914d\u67e5\u627e\u5b57\u7b26\u4e32\u3002\u8be5\u5339\u914d\u4e0d\u9700\u8981\u83b7\u53d6\u4f9b\u4ee5\u540e\u4f7f\u7528\u3002<br \/><strong>\u6ce8\u610f<\/strong>\uff1a\u9884\u67e5\u4e0d\u6d88\u8017\u5b57\u7b26\u3002<\/td>\n<td>`&#8217;Windows (?=95<\/td>\n<\/tr>\n<tr>\n<td><code>(?!pattern)<\/code><\/td>\n<td>\u8d1f\u5411\u9884\u67e5\u3002\u5728\u4efb\u4f55\u4e0d\u5339\u914d<code>pattern<\/code>\u7684\u5b57\u7b26\u4e32\u5f00\u59cb\u5904\u5339\u914d\u67e5\u627e\u5b57\u7b26\u4e32\u3002\u540c\u6837\u662f\u975e\u83b7\u53d6\u5339\u914d\u3002<br \/><strong>\u6ce8\u610f<\/strong>\uff1a\u9884\u67e5\u4e0d\u6d88\u8017\u5b57\u7b26\u3002<\/td>\n<td>`&#8217;Windows (?!95<\/td>\n<\/tr>\n<tr>\n<td><code>x | y<\/code><\/td>\n<td>\u5339\u914d<code>x<\/code>\u6216<code>y<\/code>\u3002\u8868\u793a\u4e24\u8005\u4e4b\u4e00\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>[xyz]<\/code><\/td>\n<td>\u5b57\u7b26\u96c6\u5408\u3002\u5339\u914d\u6240\u5305\u542b\u7684\u4efb\u610f\u4e00\u4e2a\u5b57\u7b26\u3002<\/td>\n<td><code>'[abc]'<\/code> \u53ef\u4ee5\u5339\u914d &quot;plain&quot; \u4e2d\u7684 &#8216;a&#8217;\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>[^xyz]<\/code><\/td>\n<td>\u8d1f\u503c\u5b57\u7b26\u96c6\u5408\u3002\u5339\u914d\u672a\u5305\u542b\u7684\u4efb\u610f\u5b57\u7b26\u3002<\/td>\n<td><code>'^[abc]'<\/code> \u53ef\u4ee5\u5339\u914d &quot;plain&quot; \u4e2d\u7684 &#8216;p&#8217;\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>[a-z]<\/code><\/td>\n<td>\u5b57\u7b26\u8303\u56f4\u3002\u5339\u914d\u6307\u5b9a\u8303\u56f4\u5185\u7684\u4efb\u610f\u5b57\u7b26\u3002<\/td>\n<td><code>'[a-z]'<\/code> \u53ef\u4ee5\u5339\u914d &#8216;a&#8217; \u5230 &#8216;z&#8217; \u8303\u56f4\u5185\u7684\u4efb\u610f\u5c0f\u5199\u5b57\u6bcd\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>[^a-z]<\/code><\/td>\n<td>\u8d1f\u503c\u5b57\u7b26\u8303\u56f4\u3002\u5339\u914d\u4efb\u4f55\u4e0d\u5728\u6307\u5b9a\u8303\u56f4\u5185\u7684\u4efb\u610f\u5b57\u7b26\u3002<\/td>\n<td><code>'^[a-z]'<\/code> \u53ef\u4ee5\u5339\u914d\u4efb\u4f55\u4e0d\u5728 &#8216;a&#8217; \u5230 &#8216;z&#8217; \u8303\u56f4\u5185\u7684\u4efb\u610f\u5b57\u7b26\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>b<\/code><\/td>\n<td>\u5355\u8bcd\u8fb9\u754c\u3002\u5339\u914d\u5355\u8bcd\u548c\u7a7a\u683c\u95f4\u7684\u4f4d\u7f6e\u3002<\/td>\n<td><code>'erb'<\/code> \u53ef\u4ee5\u5339\u914d &quot;never&quot; \u4e2d\u7684 &#8216;er&#8217;\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &quot;verb&quot; \u4e2d\u7684 &#8216;er&#8217;\u3002<\/td>\n<\/tr>\n<tr>\n<td><code>B<\/code><\/td>\n<td>\u975e\u5355\u8bcd\u8fb9\u754c\u3002\u4e0e<code>b<\/code>\u76f8\u53cd\uff0c\u7528\u4e8e\u5339\u914d\u975e\u5355\u8bcd\u8fb9\u754c\u7684\u60c5\u51b5\u3002<\/td>\n<td><code>'erB'<\/code> \u80fd\u5339\u914d &quot;verb&quot; \u4e2d\u7684 &#8216;er&#8217;\uff0c\u4f46\u4e0d\u80fd\u5339\u914d &quot;never&quot; \u4e2d\u7684 &#8216;er&#8217;\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<div class=\"table-responsive\"><table class=\"table\" >\n<thead>\n<tr>\n<th>\u8f6c\u4e49\u5e8f\u5217<\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u7b49\u4ef7\u4e8e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>.<\/code><\/td>\n<td>\u5339\u914d\u9664\u6362\u884c\u7b26\u5916\u7684\u6240\u6709\u5b57\u7b26<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td><code>cx<\/code><\/td>\n<td>\u5339\u914d\u7531 x \u6307\u660e\u7684\u63a7\u5236\u5b57\u7b26\uff08x \u4e3a A-Z \u6216 a-z\uff09<\/td>\n<td>\u5982 cM \u5339\u914d\u56de\u8f66\u7b26<\/td>\n<\/tr>\n<tr>\n<td><code>d<\/code><\/td>\n<td>\u5339\u914d\u4e00\u4e2a\u6570\u5b57\u5b57\u7b26<\/td>\n<td><code>[0-9]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>D<\/code><\/td>\n<td>\u5339\u914d\u4e00\u4e2a\u975e\u6570\u5b57\u5b57\u7b26<\/td>\n<td><code>[^0-9]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>f<\/code><\/td>\n<td>\u5339\u914d\u4e00\u4e2a\u6362\u9875\u7b26<\/td>\n<td><code>x0c<\/code>, <code>cL<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>n<\/code><\/td>\n<td>\u5339\u914d\u4e00\u4e2a\u6362\u884c\u7b26<\/td>\n<td><code>x0a<\/code>, <code>cJ<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>r<\/code><\/td>\n<td>\u5339\u914d\u4e00\u4e2a\u56de\u8f66\u7b26<\/td>\n<td><code>x0d<\/code>, <code>cM<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>s<\/code><\/td>\n<td>\u5339\u914d\u4efb\u4f55\u7a7a\u767d\u5b57\u7b26\uff0c\u5305\u62ec\u7a7a\u683c\u3001\u5236\u8868\u7b26\u7b49<\/td>\n<td><code>[ fnrtv]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>S<\/code><\/td>\n<td>\u5339\u914d\u4efb\u4f55\u975e\u7a7a\u767d\u5b57\u7b26<\/td>\n<td><code>[^ fnrtv]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>t<\/code><\/td>\n<td>\u5339\u914d\u4e00\u4e2a\u5236\u8868\u7b26<\/td>\n<td><code>x09<\/code>, <code>cI<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>v<\/code><\/td>\n<td>\u5339\u914d\u4e00\u4e2a\u5782\u76f4\u5236\u8868\u7b26<\/td>\n<td><code>x0b<\/code>, <code>cK<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>w<\/code><\/td>\n<td>\u5339\u914d\u5355\u8bcd\u5b57\u7b26\uff0c\u5305\u62ec\u4e0b\u5212\u7ebf<\/td>\n<td><code>[A-Za-z0-9_]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>W<\/code><\/td>\n<td>\u5339\u914d\u975e\u5355\u8bcd\u5b57\u7b26\uff0c\u4e0d\u5305\u62ec\u4e0b\u5212\u7ebf<\/td>\n<td><code>[^A-Za-z0-9_]<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>xn<\/code><\/td>\n<td>\u5339\u914d n\uff0c\u5176\u4e2d n \u662f\u5341\u516d\u8fdb\u5236\u8f6c\u4e49\u503c<\/td>\n<td>\u4f8b\u5982 <code>x41<\/code> \u5339\u914d &quot;A&quot;<\/td>\n<\/tr>\n<tr>\n<td><code>num<\/code><\/td>\n<td>\u5f15\u7528\u4e4b\u524d\u6355\u83b7\u7684\u7b2c num \u7ec4\u5339\u914d<\/td>\n<td>\u4f8b\u5982 <code>(.)1<\/code> \u5339\u914d\u4e24\u4e2a\u8fde\u7eed\u76f8\u540c\u5b57\u7b26<\/td>\n<\/tr>\n<tr>\n<td><code>n<\/code><\/td>\n<td>\u6807\u8bc6\u516b\u8fdb\u5236\u8f6c\u4e49\u503c\u6216\u5411\u540e\u5f15\u7528<\/td>\n<td>\u6839\u636e\u4e0a\u4e0b\u6587\u51b3\u5b9a<\/td>\n<\/tr>\n<tr>\n<td><code>nm<\/code><\/td>\n<td>\u6807\u8bc6\u516b\u8fdb\u5236\u8f6c\u4e49\u503c\u6216\u5411\u540e\u5f15\u7528<\/td>\n<td>\u6839\u636e\u4e0a\u4e0b\u6587\u51b3\u5b9a<\/td>\n<\/tr>\n<tr>\n<td><code>nml<\/code><\/td>\n<td>\u5982\u679c n \u4e3a 0-3, m \u548c l \u4e3a 0-7\uff0c\u5219\u5339\u914d\u516b\u8fdb\u5236\u8f6c\u4e49\u503c nml<\/td>\n<td>&#8211;<\/td>\n<\/tr>\n<tr>\n<td><code>un<\/code><\/td>\n<td>\u5339\u914d n\uff0c\u5176\u4e2d n \u662f\u4e00\u4e2a\u56db\u4f4d\u5341\u516d\u8fdb\u5236\u8868\u793a\u7684 Unicode \u5b57\u7b26<\/td>\n<td>\u4f8b\u5982 <code>u00A9<\/code> \u5339\u914d\u7248\u6743\u7b26\u53f7<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<p>\u4f8b\u5b50 \u5339\u914d 32 \u4f4d md5<\/p>\n<p>\/^[a-z0-9]{32}$\/<\/p>\n<h1>php \u4e0e mysql<\/h1>\n<p><a href=\"https:\/\/www.w3cschool.cn\/php\/php-mysql-select.html\">https:\/\/www.w3cschool.cn\/php\/php-mysql-select.html<\/a><\/p>\n<p>PHP \u8fde\u63a5 MySQL<\/p>\n<p>\u5728 PHP \u4f7f\u7528 MySQL \u6570\u636e\u5e93\u524d\uff0c\u4f60\u9700\u8981\u5148\u5c06\u5b83\u4eec\u8fde\u63a5\u3002<\/p>\n<p>PHP 5 \u53ca\u4ee5\u4e0a\u7248\u672c\u5efa\u8bae\u4f7f\u7528\u4ee5\u4e0b\u65b9\u5f0f\u8fde\u63a5 MySQL :<\/p>\n<p>MySQLi extension (&quot;i&quot; \u610f\u4e3a improved)<\/p>\n<p>PDO (PHP Data Objects)<\/p>\n<p>\u5728 PHP \u65e9\u8d77\u7248\u672c\u4e2d\u6211\u4eec\u4f7f\u7528 MySQL \u6269\u5c55\u3002\u4f46\u8be5\u6269\u5c55\u5728 2012 \u5e74\u5f00\u59cb\u4e0d\u5efa\u8bae\u4f7f\u7528\u3002<\/p>\n<p>\u6211\u662f\u8be5\u7528 MySQLi \uff0c\u8fd8\u662f PDO?<\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u4e00\u4e2a\u7b80\u77ed\u7684\u56de\u7b54\uff0c\u5373 &quot;\u4f60\u4e60\u60ef\u54ea\u4e2a\u5c31\u7528\u54ea\u4e2a&quot;\u3002<\/p>\n<p>MySQLi \u548c PDO \u6709\u5b83\u4eec\u81ea\u5df1\u7684\u4f18\u52bf\uff1a<\/p>\n<p>PDO \u5e94\u7528\u5728 12 \u79cd\u4e0d\u540c\u6570\u636e\u5e93\u4e2d\uff0c MySQLi \u53ea\u9488\u5bf9 MySQL \u6570\u636e\u5e93\u3002<\/p>\n<p>\u6240\u4ee5\uff0c\u5982\u679c\u4f60\u7684\u9879\u76ee\u9700\u8981\u5728\u591a\u79cd\u6570\u636e\u5e93\u4e2d\u5207\u6362\uff0c\u5efa\u8bae\u4f7f\u7528 PDO \uff0c\u8fd9\u6837\u4f60\u53ea\u9700\u8981\u4fee\u6539\u8fde\u63a5\u5b57\u7b26\u4e32\u548c\u90e8\u5206\u67e5\u8be2\u8bed\u53e5\u5373\u53ef\u3002\u4f7f\u7528 MySQLi, \u5982\u679c\u4e0d\u540c\u6570\u636e\u5e93\uff0c\u4f60\u9700\u8981\u91cd\u65b0\u6240\u6709\u4ee3\u7801\uff0c\u5305\u62ec\u67e5\u8be2\u3002<\/p>\n<p>\u4e24\u8005\u90fd\u662f\u9762\u5411\u5bf9\u8c61, \u4f46 MySQLi \u8fd8\u63d0\u4f9b\u4e86 API \u63a5\u53e3\u3002<\/p>\n<p>\u4e24\u8005\u90fd\u652f\u6301\u9884\u5904\u7406\u8bed\u53e5\u3002 \u9884\u5904\u7406\u8bed\u53e5\u53ef\u4ee5\u9632\u6b62 SQL \u6ce8\u5165\uff0c\u5bf9\u4e8e web \u9879\u76ee\u7684\u5b89\u5168\u6027\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p>MySQLi \u548c PDO \u8fde\u63a5 MySQL \u5b9e\u4f8b<\/p>\n<p>\u5728\u672c\u7ae0\u8282\u53ca\u63a5\u4e0b\u6765\u7684\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528\u4ee5\u4e0b\u4e09\u79cd\u65b9\u5f0f\u6765\u6f14\u793a PHP \u64cd\u4f5c MySQL:<\/p>\n<p>MySQLi (\u9762\u5411\u5bf9\u8c61)<\/p>\n<p>MySQLi (\u9762\u5411\u8fc7\u7a0b)<\/p>\n<p>PDO<\/p>\n<p>MySQLi Installation<\/p>\n<p>Linux \u548c Windows: \u5728 php5 mysql \u5305\u5b89\u88c5\u65f6 MySQLi \u6269\u5c55\u591a\u4e8b\u60c5\u51b5\u4e0b\u662f\u81ea\u52a8\u5b89\u88c5\u7684\u3002<\/p>\n<p>\u5b89\u88c5\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u67e5\u770b\uff1a <a href=\"http:\/\/php.net\/manual\/en\/mysqli.installation.php\">http:\/\/php.net\/manual\/en\/mysqli.installation.php<\/a><\/p>\n<p>PDO \u5b89\u88c5<\/p>\n<p>For \u5b89\u88c5\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u67e5\u770b\uff1a <a href=\"http:\/\/php.net\/manual\/en\/pdo.installation.php\">http:\/\/php.net\/manual\/en\/pdo.installation.php<\/a><\/p>\n<p>\u8fde\u63a5 MySQL<\/p>\n<p>\u5728\u6211\u4eec\u8bbf\u95ee MySQL \u6570\u636e\u5e93\u524d\uff0c\u6211\u4eec\u9700\u8981\u5148\u8fde\u63a5\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n\/\/ \u521b\u5efa\u8fde\u63a5\n$conn = new mysqli($servername, $username, $password);\n\/\/ \u68c0\u6d4b\u8fde\u63a5\nif ($conn-&gt;connect_error) {\ndie(\"Connection failed: \" . $conn-&gt;connect_error);\n}\necho \"Connected successfully\";\n?&gt;<\/code><\/pre>\n<p>\u9762\u5411\u8fc7\u7a0b<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n\/\/ \u521b\u5efa\u8fde\u63a5\n$conn = mysqli_connect($servername, $username, $password);\n\/\/ \u68c0\u6d4b\u8fde\u63a5\nif (!$conn) {\ndie(\"Connection failed: \" . mysqli_connect_error());\n}\necho \"Connected successfully\";\n?&gt;<\/code><\/pre>\n<p>PDO<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\ntry {\n$conn = new PDO(\"mysql:host=$servername;dbname=myDB\", $username,\n$password);\necho \"Connected successfully\";\n}\ncatch(PDOException $e)\n{\necho $e-&gt;getMessage();\n}\n?&gt;<\/code><\/pre>\n<p>\u5173\u95ed\u8fde\u63a5<\/p>\n<p>\u8fde\u63a5\u5728\u811a\u672c\u6267\u884c\u5b8c\u540e\u4f1a\u81ea\u52a8\u5173\u95ed\u3002\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6765\u5173\u95ed\u8fde\u63a5\uff1a<\/p>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u5bf9\u8c61)<\/p>\n<p>$conn-&gt;close();<\/p>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u8fc7\u7a0b)<\/p>\n<p>mysqli_close($conn);<\/p>\n<p>\u5b9e\u4f8b (PDO)<\/p>\n<p>$conn = null;<\/p>\n<p>\u73b0\u5728\uff0c\u4f60\u5df2\u7ecf\u77e5\u9053\u5982\u4f55\u5c06 MySQL \u6570\u636e\u5e93\u8fde\u63a5\u5230 PHP \u4e86\uff0c\u63a5\u4e0b\u6765\uff0c\u4f60\u5e94\u8be5\u4e86\u89e3 PHP \u662f\u5982\u4f55\u521b\u5efa\u6570\u636e\u5e93\u7684\uff01<\/p>\n<p>PHP \u521b\u5efa MySQL \u8868<\/p>\n<p>\u5728 PHP \u4e2d\u521b\u5efa\u5b8c\u6570\u636e\u5e93\u4e4b\u540e\uff0c\u6211\u4eec\u9700\u8981\u5728\u6570\u636e\u5e93\u4e2d\u521b\u5efa\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u7684\u6570\u636e\u8868\u3002<\/p>\n<p>\u4e00\u4e2a\u6570\u636e\u8868\u6709\u4e00\u4e2a\u552f\u4e00\u540d\u79f0\uff0c\u5e76\u6709\u884c\u548c\u5217\u7ec4\u6210\u3002<\/p>\n<p>\u4f7f\u7528 MySQLi \u548c PDO \u521b\u5efa MySQL \u8868<\/p>\n<p>CREATE TABLE \u8bed\u53e5\u7528\u4e8e\u521b\u5efa MySQL \u8868\u3002<\/p>\n<p>\u521b\u5efa\u8868\u524d\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528 use myDB \u6765\u9009\u62e9\u8981\u64cd\u4f5c\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<p>use myDB;<\/p>\n<p>\u6211 \u4eec \u5c06 \u521b \u5efa \u4e00 \u4e2a \u540d \u4e3a &quot;MyGuests&quot; \u7684 \u8868 \uff0c \u6709 5 \u4e2a \u5217 \uff1a &quot;id&quot;, &quot;firstname&quot;,<\/p>\n<p>&quot;lastname&quot;, &quot;email&quot; \u548c &quot;reg_date&quot;:<\/p>\n<p>CREATE TABLE MyGuests (<\/p>\n<p>id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,<\/p>\n<p>firstname VARCHAR(30) NOT NULL,<\/p>\n<p>lastname VARCHAR(30) NOT NULL,<\/p>\n<p>email VARCHAR(50),<\/p>\n<p>reg_date  TIMESTAMP<\/p>\n<p>)<\/p>\n<p>\u4e0a\u8868\u4e2d\u7684\u6ce8\u610f\u4e8b\u9879:<\/p>\n<p>\u6570\u636e\u7c7b\u578b\u6307\u5b9a\u5217\u53ef\u4ee5\u5b58\u50a8\u4ec0\u4e48\u7c7b\u578b\u7684\u6570\u636e\u3002\u5b8c\u6574\u7684\u6570\u636e\u7c7b\u578b\u8bf7\u53c2\u8003\u6211\u4eec\u7684 \u6570\u636e\u7c7b\u578b\u53c2\u8003\u624b\u518c\u3002<\/p>\n<p>\u5728\u8bbe\u7f6e\u4e86\u6570\u636e\u7c7b\u578b\u540e\uff0c\u4f60\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u5217\u6307\u5b9a\u5176\u4ed6\u9009\u9879\u7684\u5c5e\u6027\uff1a<\/p>\n<p>NOT NULL &#8211; \u6bcf\u4e00\u884c\u90fd\u5fc5\u987b\u542b\u6709\u503c\uff08\u4e0d\u80fd\u4e3a\u7a7a\uff09\uff0cnull \u503c\u662f\u4e0d\u5141\u8bb8\u7684\u3002<\/p>\n<p>DEFAULT value &#8211; \u8bbe\u7f6e\u9ed8\u8ba4\u503c<\/p>\n<p>UNSIGNED &#8211; \u4f7f\u7528\u65e0\u7b26\u53f7\u6570\u503c\u7c7b\u578b\uff0c0 \u53ca\u6b63\u6570<\/p>\n<p>AUTO INCREMENT &#8211; \u8bbe\u7f6e MySQL \u5b57\u6bb5\u7684\u503c\u5728\u65b0\u589e\u8bb0\u5f55\u65f6\u6bcf\u6b21\u81ea\u52a8\u589e\u957f 1<\/p>\n<p>PRIMARY KEY &#8211; \u8bbe\u7f6e\u6570\u636e\u8868\u4e2d\u6bcf\u6761\u8bb0\u5f55\u7684\u552f\u4e00\u6807\u8bc6\u3002 \u901a\u5e38\u5217\u7684 PRIMARY KEY<\/p>\n<p>\u8bbe\u7f6e\u4e3a ID \u6570\u503c\uff0c\u4e0e AUTO_INCREMENT \u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<p>\u6bcf\u4e2a\u8868\u90fd\u5e94\u8be5\u6709\u4e00\u4e2a\u4e3b\u952e(\u672c\u5217\u4e3a &quot;id&quot; \u5217)\uff0c\u4e3b\u952e\u5fc5\u987b\u5305\u542b\u552f\u4e00\u7684\u503c\u3002<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u5728 PHP \u4e2d\u521b\u5efa\u8868\uff1a<\/p>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u5bf9\u8c61)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDB\";\n\/\/ \u521b\u5efa\u8fde\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\/\/ \u68c0\u6d4b\u8fde\u63a5\nif ($conn-&gt;connect_error) {\ndie(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n\/\/ sql to create table\n$sql = \"CREATE TABLE MyGuests (\nid INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\nfirstname VARCHAR(30) NOT NULL,\nlastname VARCHAR(30) NOT NULL,\nemail VARCHAR(50),\nreg_date TIMESTAMP\n)\";\nif ($conn-&gt;query($sql) === TRUE) {\necho \"Table MyGuests created successfully\";\n} else {\necho \"Error creating table: \" . $conn-&gt;error;\n}\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u8fc7\u7a0b)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDB\";\n\/\/ \u521b\u5efa\u8fde\u63a5\n$conn = mysqli_connect($servername, $username, $password, $dbname);\n\/\/ \u68c0\u6d4b\u8fde\u63a5\nif (!$conn) {\ndie(\"Connection failed: \" . mysqli_connect_error());\n}\n\/\/ sql to create table\n$sql = \"CREATE TABLE MyGuests (\nid INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\nfirstname VARCHAR(30) NOT NULL,\nlastname VARCHAR(30) NOT NULL,\nemail VARCHAR(50),\nreg_date TIMESTAMP\n)\";\nif (mysqli_query($conn, $sql)) {\necho \"Table MyGuests created successfully\";\n} else {\necho \"Error creating table: \" . mysqli_error($conn);\n}\nmysqli_close($conn);\n?&gt;<\/code><\/pre>\n<p>\u5b9e\u4f8b (PDO)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDBPDO\";\ntry {\n$conn = new PDO(\"mysql:host=$servername;dbname=$dbname\", $username,\n$password);\n\/\/ set the PDO error mode to exception\n$conn-&gt;setAttribute(PDO::ATTR_ERRMODE,\nPDO::ERRMODE_EXCEPTION);\n\/\/ sql to create table\n$sql = \"CREATE TABLE MyGuests (\nid INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,\nfirstname VARCHAR(30) NOT NULL,\nlastname VARCHAR(30) NOT NULL,\nemail VARCHAR(50),\nreg_date TIMESTAMP\n)\";\n\/\/ use exec() because no results are returned\n$conn-&gt;exec($sql);\necho \"Table MyGuests created successfully\";\n}\ncatch(PDOException $e)\n{\necho $sql . \"&lt;br&gt;\" . $e-&gt;getMessage();\n}\n$conn = null;\n?&gt;<\/code><\/pre>\n<p>\u73b0\u5728\uff0c\u4f60\u7684 MySQL \u6570\u636e\u5e93\u5df2\u7ecf\u521b\u5efa\u597d\uff0c\u5e76\u4e14\u6709\u4e86\u9700\u8981\u7684\u8868\u683c\uff0c\u4f46\u662f\u8fd9\u8fd8\u4e0d\u591f\uff0c\u56e0\u4e3a\u6570\u636e\u8868\u4e2d\u8fd8\u6ca1\u6709\u6570\u636e\uff0c\u6b64\u65f6\u8868\u8fd8\u53ea\u662f\u4e2a\u67b6\u5b50\uff0c\u6240\u4ee5\uff0c\u6211\u4eec\u9700\u8981\u7ee7\u7eed\u5b8c\u5584\u6570\u636e\u8868\uff0c\u4e3a\u5b83\u63d2\u5165\u4e00\u4e9b\u6570\u636e\uff01<\/p>\n<p>\u4f7f\u7528 MySQLi \u548c PDO \u5411 MySQL \u63d2\u5165\u6570\u636e<\/p>\n<p>\u5728\u521b\u5efa\u5b8c\u6570\u636e\u5e93\u548c\u8868\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5411\u8868\u4e2d\u6dfb\u52a0\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0b\u4e3a\u4e00\u4e9b\u8bed\u6cd5\u89c4\u5219\uff1a<\/p>\n<p>PHP \u4e2d SQL \u67e5\u8be2\u8bed\u53e5\u5fc5\u987b\u4f7f\u7528\u5f15\u53f7<\/p>\n<p>\u5728 SQL \u67e5\u8be2\u8bed\u53e5\u4e2d\u7684\u5b57\u7b26\u4e32\u503c\u5fc5\u987b\u52a0\u5f15\u53f7<\/p>\n<p>\u6570\u503c\u7684\u503c\u4e0d\u9700\u8981\u5f15\u53f7<\/p>\n<p>NULL \u503c\u4e0d\u9700\u8981\u5f15\u53f7<\/p>\n<p>INSERT INTO \u8bed\u53e5\u901a\u5e38\u7528\u4e8e\u5411 MySQL \u8868\u6dfb\u52a0\u65b0\u7684\u8bb0\u5f55\uff1a<\/p>\n<p>INSERT INTO table_name (column1, column2, column3,&#8230;)<\/p>\n<p>VALUES (value1, value2, value3,&#8230;)<\/p>\n<p>\u5b66\u4e60\u66f4\u591a\u5173\u4e8e SQL \u77e5\u8bc6\uff0c\u8bf7\u67e5\u770b SQL \u6559\u7a0b\u3002<\/p>\n<p>\u5728 \u524d \u9762 \u7684 \u51e0 \u4e2a \u7ae0 \u8282 \u4e2d \u6211 \u4eec \u5df2 \u7ecf \u521b \u5efa \u4e86 \u8868 &quot;MyGuests&quot; \uff0c \u8868 \u5b57 \u6bb5 \u6709 : &quot;id&quot;,<\/p>\n<p>&quot;firstname&quot;, &quot;lastname&quot;, &quot;email&quot; \u548c &quot;reg_date&quot;\u3002 \u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u5f00\u59cb\u5411\u8868\u586b\u5145\u6570\u636e\u3002Note \u6ce8\u610f\uff1a \u5982\u679c\u5217\u8bbe\u7f6e AUTO_INCREMENT (\u5982 &quot;id&quot; \u5217) \u6216 TIMESTAMP(\u5982 &quot;reg_date&quot; \u5217),\uff0c\u6211\u4eec\u5c31\u4e0d\u9700\u8981\u5728 SQL \u67e5\u8be2\u8bed\u53e5\u4e2d\u6307\u5b9a\u503c\uff1b MySQL \u4f1a\u81ea\u52a8\u4e3a\u8be5\u5217\u6dfb\u52a0\u503c\u3002<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u5411 &quot;MyGuests&quot; \u8868\u6dfb\u52a0\u4e86\u65b0\u7684\u8bb0\u5f55:<\/p>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u5bf9\u8c61)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDB\";\n\/\/ \u521b\u5efa\u8fde\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\/\/ \u68c0\u6d4b\u8fde\u63a5\nif ($conn-&gt;connect_error) {\ndie(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n$sql = \"INSERT INTO MyGuests (firstname, lastname, email)\nVALUES ('John', 'Doe', 'john@example.com')\";\nif ($conn-&gt;query($sql) === TRUE) {\necho \"New record created successfully\";\n} else {\necho \"Error: \" . $sql . \"&lt;br&gt;\" . $conn-&gt;error;\n}\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u8fc7\u7a0b)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDB\";\n\/\/ \u521b\u5efa\u8fde\u63a5\n$conn = mysqli_connect($servername, $username, $password, $dbname);\n\/\/ \u68c0\u6d4b\u8fde\u63a5\nif (!$conn) {\ndie(\"Connection failed: \" . mysqli_connect_error());\n}\n$sql = \"INSERT INTO MyGuests (firstname, lastname, email)\nVALUES ('John', 'Doe', 'john@example.com')\";\nif (mysqli_query($conn, $sql)) {\necho \"New record created successfully\";\n} else {\necho \"Error: \" . $sql . \"&lt;br&gt;\" . mysqli_error($conn);\n}\nmysqli_close($conn);\n?&gt;<\/code><\/pre>\n<p>\u5b9e\u4f8b (PDO)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDBPDO\";\ntry {\n$conn = new PDO(\"mysql:host=$servername;dbname=$dbname\", $username,\n$password);\n\/\/ set the PDO error mode to exception\n$conn-&gt;setAttribute(PDO::ATTR_ERRMODE,\nPDO::ERRMODE_EXCEPTION);\n$sql = \"INSERT INTO MyGuests (firstname, lastname, email)\nVALUES ('John', 'Doe', 'john@example.com')\";\n\/\/ use exec() because no results are returned\n$conn-&gt;exec($sql);\necho \"New record created successfully\";\n}\ncatch(PDOException $e)\n{\necho $sql . \"&lt;br&gt;\" . $e-&gt;getMessage();\n}\n$conn = null;\n?&gt;<\/code><\/pre>\n<p>\u5176\u5b9e\uff0c\u4f60\u8fd8\u53ef\u4ee5\u5728 PHP \u7684 MySQL \u6570\u636e\u5e93\u4e2d\u63d2\u5165\u591a\u6761\u6570\u636e\uff0c\u8fd9\u5c06\u5728\u4e0b\u9762\u7684\u4e00\u8282\u5185\u5bb9\u4e2d\u63d0\u53ca\u3002<\/p>\n<p>PHP MySQL \u63d2\u5165\u591a\u6761\u6570\u636e<\/p>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cINSERT \u8bed\u53e5\u53ea\u80fd\u5411 MySQL \u6570\u636e\u5e93\u6dfb\u52a0\u4e00\u6761\u8bed\u53e5\uff0c\u800c\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u51fd\u6570\u6279\u91cf\u7684\u5411\u6570\u636e\u8868\u63d2\u5165\u591a\u6761\u6570\u636e\u3002\u4f7f\u7528 MySQLi \u548c PDO \u5411 MySQL \u63d2\u5165\u591a\u6761\u6570\u636e<\/p>\n<p>mysqli_multi_query() \u51fd\u6570\u53ef\u7528\u6765\u6267\u884c\u591a\u6761 SQL \u8bed\u53e5\u3002<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u5411 &quot;MyGuests&quot; \u8868\u6dfb\u52a0\u4e86\u4e09\u6761\u65b0\u7684\u8bb0\u5f55\uff1a<\/p>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u5bf9\u8c61)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password =\n\"password\";\n$dbname =\n\"myDB\";\n\/\/ \u521b\u5efa\u94fe\u63a5\n$conn =\nnew mysqli($servername, $username, $password, $dbname);\n\/\/ \u68c0\u67e5\u94fe\u63a5\nif ($conn-&gt;connect_error) {\ndie(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n$sql = \"INSERT INTO\nMyGuests (firstname, lastname, email)\nVALUES ('John', 'Doe', 'john@example.com');\";\n$sql .= \"INSERT INTO\nMyGuests (firstname, lastname, email)\nVALUES ('Mary', 'Moe', 'mary@example.com');\";\n$sql .= \"INSERT INTO\nMyGuests (firstname, lastname, email)\nVALUES ('Julie', 'Dooley', 'julie@example.com')\";\nif ($conn-&gt;multi_query($sql) === TRUE) {\necho \"New\nrecords created successfully\";\n} else {\necho\n\"Error: \" . $sql . \"\n\" . $conn-&gt;error;\n}\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<p>\u6bcf\u4e2a SQL \u8bed\u53e5\u5fc5\u987b\u7528\u5206\u53f7\u9694\u5f00<\/p>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u8fc7\u7a0b)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password =\n\"password\";\n$dbname =\n\"myDB\";\n\/\/ \u521b\u5efa\u94fe\u63a5\n$conn = mysqli_connect($servername, $username, $password,\n$dbname);\n\/\/ \u68c0\u67e5\u94fe\u63a5\nif (!$conn) {\ndie(\"Connection\nfailed: \" . mysqli_connect_error());\n}\n$sql = \"INSERT INTO\nMyGuests (firstname, lastname, email)\nVALUES ('John', 'Doe', 'john@example.com');\";\n$sql .= \"INSERT INTO\nMyGuests (firstname, lastname, email)\nVALUES ('Mary', 'Moe', 'mary@example.com');\";\n$sql .= \"INSERT INTO\nMyGuests (firstname, lastname, email)\nVALUES ('Julie', 'Dooley', 'julie@example.com')\";\nif (mysqli_multi_query($conn, $sql)) {\necho \"New\nrecords\ncreated successfully\";\n} else {\necho \"Error: \"\n. $sql . \"\n\" . mysqli_error($conn);\n}\nmysqli_close($conn);\n?&gt;<\/code><\/pre>\n<p>\u5b9e\u4f8b (PDO)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname =\n\"myDBPDO\";\ntry {\n$conn = new PDO(\"mysql:host=$servername;dbname=$dbname\",\n$username, $password);\n\/\/ set the PDO error mode to exception\n$conn-&gt;setAttribute(PDO::ATTR_ERRMODE,\nPDO::ERRMODE_EXCEPTION);\n\/\/ \u5f00\u59cb\u4e8b\u52a1\n$conn-&gt;beginTransaction();\n\/\/ SQL \u8bed\u53e5\n$conn-&gt;exec(\"INSERT INTO MyGuests (firstname, lastname, email)\nVALUES ('John', 'Doe', 'john@example.com')\");\n$conn-&gt;exec(\"INSERT INTO MyGuests (firstname, lastname, email)\nVALUES ('Mary', 'Moe', 'mary@example.com')\");\n$conn-&gt;exec(\"INSERT INTO MyGuests (firstname, lastname, email)\nVALUES ('Julie', 'Dooley', 'julie@example.com')\");\n\/\/ commit the transaction\n$conn-&gt;commit();\necho \"New records created successfully\";\n}\ncatch(PDOException $e)\n{\n\/\/ roll back the transaction if something failed\n$conn-&gt;rollback();\necho $sql . \"\n\" . $e-&gt;getMessage();\n}\n$conn = null;\n?&gt;<\/code><\/pre>\n<p>\u4f7f\u7528\u9884\u5904\u7406\u8bed\u53e5<\/p>\n<p>mysqli \u6269\u5c55\u63d0\u4f9b\u4e86\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u7528\u4e8e\u63d2\u5165\u8bed\u53e5\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u9884\u5904\u7406\u8bed\u53e5\u53ca\u7ed1\u5b9a\u53c2\u6570\u3002<\/p>\n<p>mysql \u6269\u5c55\u53ef\u4ee5\u4e0d\u5e26\u6570\u636e\u53d1\u9001\u8bed\u53e5\u6216\u67e5\u8be2\u5230 mysql \u6570\u636e\u5e93\u3002 \u4f60\u53ef\u4ee5\u5411\u5217\u5173\u8054\u6216 &quot;<\/p>\n<p>\u7ed1\u5b9a&quot; \u53d8\u91cf\u3002<\/p>\n<p>Example (MySQLi \u4f7f\u7528\u9884\u5904\u7406\u8bed\u53e5)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password =\n\"password\";\n$dbname =\n\"myDB\";\n\/\/ Create connection\n$conn =\nnew mysqli($servername, $username, $password, $dbname);\n\/\/ Check connection\nif ($conn-&gt;connect_error) {\ndie(\"Connection failed: \" . $conn-&gt;connect_error);\n} else {\n$sql = \"INSERT INTO\nMyGuests (firstname, lastname, email) VALUES(?, ?, ?)\";\n\/\/ \u4e3a mysqli_stmt_prepare() \u521d\u59cb\u5316\nstatement \u5bf9\u8c61\n$stmt =\nmysqli_stmt_init($conn);\n\/\/\u9884\u5904\u7406\u8bed\u53e5\nif (mysqli_stmt_prepare($stmt, $sql)) {\n\/\/ \u7ed1\u5b9a\u53c2\u6570\nmysqli_stmt_bind_param($stmt, 'sss', $firstname, $lastname, $email);\n\/\/ \u8bbe\u7f6e\u53c2\u6570\u5e76\u6267\u884c\n$firstname = 'John';\n$lastname\n= 'Doe';\n$email =\n'john@example.com';\nmysqli_stmt_execute($stmt);\n$firstname = 'Mary';\n$lastname\n= 'Moe';\n$email =\n'mary@example.com';\nmysqli_stmt_execute($stmt);\n$firstname = 'Julie';\n$lastname = 'Dooley';\n$email =\n'julie@example.com';\nmysqli_stmt_execute($stmt);\n}\n}\n?&gt;<\/code><\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\u4ee5\u4e0a\u5b9e\u4f8b\u4e2d\u4f7f\u7528\u6a21\u5757\u5316\u6765\u5904\u7406\u95ee\u9898\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4ee3\u7801\u5757\u5b9e\u73b0<\/p>\n<p>\u66f4\u7b80\u5355\u7684\u8bfb\u53d6\u548c\u7ba1\u7406\u3002<\/p>\n<p>\u6ce8\u610f\u53c2\u6570\u7684\u7ed1\u5b9a\u3002\u8ba9\u6211\u4eec\u770b\u4e0b mysqli_stmt_bind_param() \u4e2d\u7684\u4ee3\u7801\uff1a<\/p>\n<p>mysqli_stmt_bind_param($stmt, &#8216;sss&#8217;, $firstname, $lastname, $email);<\/p>\n<p>\u8be5\u51fd\u6570\u7ed1\u5b9a\u53c2\u6570\u67e5\u8be2\u5e76\u5c06\u53c2\u6570\u4f20\u9012\u7ed9\u6570\u636e\u5e93\u3002\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f &quot;sss&quot; \u3002\u4ee5\u4e0b\u5217\u8868\u5c55\u793a\u4e86\u53c2\u6570\u7684\u7c7b\u578b\u3002 s \u5b57\u7b26\u544a\u8bc9 mysql \u53c2\u6570\u662f\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u53ef\u4ee5\u662f\u4ee5\u4e0b\u56db\u79cd\u53c2\u6570\uff1a<\/p>\n<p>i &#8211; integer<\/p>\n<p>d &#8211; double<\/p>\n<p>s &#8211; string<\/p>\n<p>b &#8211; BLOB<\/p>\n<p>\u6bcf\u4e2a\u53c2\u6570\u5fc5\u987b\u6307\u5b9a\u7c7b\u578b\uff0c\u6765\u4fdd\u8bc1\u6570\u636e\u7684\u5b89\u5168\u6027\u3002\u901a\u8fc7\u7c7b\u578b\u7684\u5224\u65ad\u53ef\u4ee5\u51cf\u5c11 SQL<\/p>\n<p>\u6ce8\u5165\u6f0f\u6d1e\u5e26\u6765\u7684\u98ce\u9669\u3002<\/p>\n<h2>PHP MySQL \u9884\u5904\u7406\u8bed\u53e5<\/h2>\n<p>MySQL \u4ece 4.1 \u7248\u672c\u5f00\u59cb\u63d0\u4f9b\u4e86\u4e00\u79cd\u540d\u4e3a\u9884\u5904\u7406\u8bed\u53e5\uff08prepared statement\uff09\u7684\u673a\u5236\u3002<\/p>\n<p>MySQL \u9884\u5904\u7406\u8bed\u53e5\u4e0d\u4ec5\u5927\u5927\u51cf\u5c11\u4e86\u9700\u8981\u4f20\u8f93\u7684\u6570\u636e\u91cf\uff0c\u8fd8\u63d0\u9ad8\u4e86\u547d\u4ee4\u7684\u5904\u7406\u6548\u7387\u3002<\/p>\n<p>\u9884\u5904\u7406\u8bed\u53e5\u5bf9\u4e8e\u9632\u6b62 MySQL \u6ce8\u5165\u662f\u975e\u5e38\u6709\u7528\u7684\u3002<\/p>\n<p>\u9884\u5904\u7406\u8bed\u53e5\u53ca\u7ed1\u5b9a\u53c2\u6570<\/p>\n<p>\u9884\u5904\u7406\u8bed\u53e5\u7528\u4e8e\u6267\u884c\u591a\u4e2a\u76f8\u540c\u7684 SQL \u8bed\u53e5\uff0c\u5e76\u4e14\u6267\u884c\u6548\u7387\u66f4\u9ad8\u3002<\/p>\n<p>\u9884\u5904\u7406\u8bed\u53e5\u7684\u5de5\u4f5c\u539f\u7406\u5982\u4e0b\uff1a<\/p>\n<p>\u9884\u5904\u7406\uff1a\u521b\u5efa SQL \u8bed\u53e5\u6a21\u677f\u5e76\u53d1\u9001\u5230\u6570\u636e\u5e93\u3002\u9884\u7559\u7684\u503c\u4f7f\u7528\u53c2\u6570 &quot;?&quot; \u6807\u8bb0 \u3002<\/p>\n<p>\u4f8b\u5982\uff1aINSERT INTO MyGuests (firstname, lastname, email) VALUES(?, ?, ?)<\/p>\n<p>\u6570\u636e\u5e93\u89e3\u6790\uff0c\u7f16\u8bd1\uff0c\u5bf9 SQL \u8bed\u53e5\u6a21\u677f\u6267\u884c\u67e5\u8be2\u4f18\u5316\uff0c\u5e76\u5b58\u50a8\u7ed3\u679c\u4e0d\u8f93\u51fa<\/p>\n<p>\u6267\u884c\uff1a\u6700\u540e\uff0c\u5c06\u5e94\u7528\u7ed1\u5b9a\u7684\u503c\u4f20\u9012\u7ed9\u53c2\u6570\uff08&quot;?&quot; \u6807\u8bb0\uff09\uff0c\u6570\u636e\u5e93\u6267\u884c\u8bed\u53e5\u3002\u5e94\u7528<\/p>\n<p>\u53ef\u4ee5\u591a\u6b21\u6267\u884c\u8bed\u53e5\uff0c\u5982\u679c\u53c2\u6570\u7684\u503c\u4e0d\u4e00\u6837\u3002<\/p>\n<p>\u76f8\u6bd4\u4e8e\u76f4\u63a5\u6267\u884c SQL \u8bed\u53e5\uff0c\u9884\u5904\u7406\u8bed\u53e5\u6709\u4e24\u4e2a\u4e3b\u8981\u4f18\u70b9\uff1a<\/p>\n<p>\u9884\u5904\u7406\u8bed\u53e5\u5927\u5927\u51cf\u5c11\u4e86\u5206\u6790\u65f6\u95f4\uff0c\u53ea\u505a\u4e86\u4e00\u6b21\u67e5\u8be2\uff08\u867d\u7136\u8bed\u53e5\u591a\u6b21\u6267\u884c\uff09<\/p>\n<p>\u7ed1\u5b9a\u53c2\u6570\u51cf\u5c11\u4e86\u670d\u52a1\u5668\u5e26\u5bbd\uff0c\u4f60\u53ea\u9700\u8981\u53d1\u9001\u67e5\u8be2\u7684\u53c2\u6570\uff0c\u800c\u4e0d\u662f\u6574\u4e2a\u8bed\u53e5<\/p>\n<p>\u9884\u5904\u7406\u8bed\u53e5\u9488\u5bf9 SQL \u6ce8\u5165\u662f\u975e\u5e38\u6709\u7528\u7684\uff0c\u56e0\u4e3a \u53c2\u6570\u503c\u53d1\u9001\u540e\u4f7f\u7528\u4e0d\u540c\u7684\u534f\u8bae\uff0c\u4fdd\u8bc1\u4e86\u6570\u636e\u7684\u5408\u6cd5\u6027\u3002<\/p>\n<p>MySQLi \u9884\u5904\u7406\u8bed\u53e5<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u5728 MySQLi \u4e2d\u4f7f\u7528\u4e86\u9884\u5904\u7406\u8bed\u53e5\uff0c\u5e76\u7ed1\u5b9a\u4e86\u76f8\u5e94\u7684\u53c2\u6570:<\/p>\n<p>\u5b9e\u4f8b (MySQLi \u4f7f\u7528\u9884\u5904\u7406\u8bed\u53e5)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDB\";\n\/\/ \u521b\u5efa\u8fde\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\/\/ \u68c0\u6d4b\u8fde\u63a5\nif ($conn-&gt;connect_error) {\ndie(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n\/\/ prepare and bind\n$stmt = $conn-&gt;prepare(\"INSERT INTO MyGuests (firstname, lastname, email)\nVALUES(?, ?, ?)\");\n$stmt-&gt;bind_param(\"sss\", $firstname, $lastname, $email);\n\/\/ \u8bbe\u7f6e\u53c2\u6570\u5e76\u6267\u884c\n$firstname = \"John\";\n$lastname = \"Doe\";\n$email = \"john@example.com\";\n$stmt-&gt;execute();\n$firstname = \"Mary\";\n$lastname = \"Moe\";\n$email = \"mary@example.com\";\n$stmt-&gt;execute();\n$firstname = \"Julie\";\n$lastname = \"Dooley\";\n$email = \"julie@example.com\";\n$stmt-&gt;execute();\necho \"New records created successfully\";\n$stmt-&gt;close();\n$conn-&gt;close();\n?&gt;\n\u89e3\u6790\u4ee5\u4e0b\u5b9e\u4f8b\u7684\u6bcf\u884c\u4ee3\u7801:\n\"INSERT INTO MyGuests (firstname, lastname, email) VALUES(?, ?, ?)\"<\/code><\/pre>\n<p>\u5728 SQL \u8bed\u53e5\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u95ee\u53f7 (?)\uff0c\u5728\u6b64\u6211\u4eec\u53ef\u4ee5\u5c06\u95ee\u53f7\u66ff\u6362\u4e3a\u6574\u578b\uff0c\u5b57\u7b26\u4e32\uff0c\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u578b\u548c\u5e03\u5c14\u503c\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u6765\u770b\u4e0b bind_param() \u51fd\u6570\uff1a<\/p>\n<p>$stmt-&gt;bind_param(&quot;sss&quot;, $firstname, $lastname, $email);<\/p>\n<p>\u8be5\u51fd\u6570\u7ed1\u5b9a\u4e86 SQL \u7684\u53c2\u6570\uff0c\u4e14\u544a\u8bc9\u6570\u636e\u5e93\u53c2\u6570\u7684\u503c\u3002 &quot;sss&quot; \u53c2\u6570\u5217\u5904\u7406\u5176\u4f59\u53c2<\/p>\n<p>\u6570\u7684\u6570\u636e\u7c7b\u578b\u3002s \u5b57\u7b26\u544a\u8bc9\u6570\u636e\u5e93\u8be5\u53c2\u6570\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u53c2\u6570\u6709\u4ee5\u4e0b\u56db\u79cd\u7c7b\u578b:<\/p>\n<p>i &#8211; integer\uff08\u6574\u578b\uff09<\/p>\n<p>d &#8211; double\uff08\u53cc\u7cbe\u5ea6\u6d6e\u70b9\u578b\uff09<\/p>\n<p>s &#8211; string\uff08\u5b57\u7b26\u4e32\uff09<\/p>\n<p>b &#8211; BLOB\uff08\u5e03\u5c14\u503c\uff09<\/p>\n<p>\u6bcf\u4e2a\u53c2\u6570\u90fd\u9700\u8981\u6307\u5b9a\u7c7b\u578b\u3002<\/p>\n<p>\u901a\u8fc7\u544a\u8bc9\u6570\u636e\u5e93\u53c2\u6570\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u964d\u4f4e SQL \u6ce8\u5165\u7684\u98ce\u9669\u3002<\/p>\n<p>Note \u6ce8\u610f\uff1a \u5982\u679c\u4f60\u60f3\u63d2\u5165\u5176\u4ed6\u6570\u636e\uff08\u7528\u6237\u8f93\u5165\uff09\uff0c\u5bf9\u6570\u636e\u7684\u9a8c\u8bc1\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p>PDO \u4e2d\u7684\u9884\u5904\u7406\u8bed\u53e5<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u6211\u4eec\u5728 PDO \u4e2d\u4f7f\u7528\u4e86\u9884\u5904\u7406\u8bed\u53e5\u5e76\u7ed1\u5b9a\u53c2\u6570:<\/p>\n<p>\u5b9e\u4f8b (PDO \u4f7f\u7528\u9884\u5904\u7406\u8bed\u53e5)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDBPDO\";\ntry {\n$conn = new PDO(\"mysql:host=$servername;dbname=$dbname\", $username,\n$password);\n\/\/ \u8bbe\u7f6e PDO \u9519\u8bef\u6a21\u5f0f\u4e3a\u5f02\u5e38\n$conn-&gt;setAttribute(PDO::ATTR_ERRMODE,\nPDO::ERRMODE_EXCEPTION);\n\/\/ \u9884\u5904\u7406 SQL \u5e76\u7ed1\u5b9a\u53c2\u6570\n$stmt = $conn-&gt;prepare(\"INSERT INTO MyGuests (firstname, lastname, email)\nVALUES (:firstname, :lastname, :email)\");\n$stmt-&gt;bindParam(':firstname', $firstname);\n$stmt-&gt;bindParam(':lastname', $lastname);\n$stmt-&gt;bindParam(':email', $email);\n\/\/ \u63d2\u5165\u884c\n$firstname = \"John\";\n$lastname = \"Doe\";\n$email = \"john@example.com\";\n$stmt-&gt;execute();\n\/\/ \u63d2\u5165\u5176\u4ed6\u884c\n$firstname = \"Mary\";\n$lastname = \"Moe\";\n$email = \"mary@example.com\";\n$stmt-&gt;execute();\n\/\/ \u63d2\u5165\u5176\u4ed6\u884c\n$firstname = \"Julie\";\n$lastname = \"Dooley\";\n$email = \"julie@example.com\";\n$stmt-&gt;execute();\necho \"New records created successfully\";\n}\ncatch(PDOException $e)\n{\necho $sql . \"&lt;br&gt;\" . $e-&gt;getMessage();\n}\n$conn = null;\n?&gt;<\/code><\/pre>\n<p>PHP MySQL \u8bfb\u53d6\u6570\u636e<\/p>\n<p>\u5f53 PHP \u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\u540e\uff0c\u9700\u8981\u5411\u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e\uff1f\u90a3\u4e48\u600e\u4e48\u8bfb\u53d6\u5462\uff1f<\/p>\n<p>\u4e00\u8d77\u6765\u770b\u770b\u3002<\/p>\n<p>\u4ece MySQL \u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e<\/p>\n<p>SELECT \u8bed\u53e5\u7528\u4e8e\u4ece\u6570\u636e\u8868\u4e2d\u8bfb\u53d6\u6570\u636e:<\/p>\n<p>SELECT column_name(s) FROM table_name<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 * \u53f7\u6765\u8bfb\u53d6\u6240\u6709\u6570\u636e\u8868\u4e2d\u7684\u5b57\u6bb5\uff1a<\/p>\n<p>SELECT * FROM table_name<\/p>\n<p>\u5982\u9700\u5b66\u4e60\u66f4\u591a\u5173\u4e8e SQL \u7684\u77e5\u8bc6\uff0c\u8bf7\u8bbf\u95ee\u6211\u4eec\u7684 SQL \u6559\u7a0b\u3002<\/p>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u4e2d\u6211\u4eec\u4ece\u8868 MyGuests \u8bfb\u53d6\u4e86 id, firstname \u548c lastname \u5217\u7684\u6570\u636e\u5e76\u663e<\/p>\n<p>\u793a\u5728\u9875\u9762\u4e0a\uff1a<\/p>\n<p>\u5b9e\u4f8b (MySQLi &#8211; \u9762\u5411\u5bf9\u8c61)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDB\";\n\/\/ \u521b\u5efa\u8fde\u63a5\n$conn = mysqli_connect($servername, $username, $password, $dbname);\n\/\/ \u68c0\u6d4b\u8fde\u63a5\nif ($conn-&gt;connect_error) {\ndie(\"Connection failed: \" . $conn-&gt;connect_error);\n}\n$sql = \"SELECT id, firstname, lastname FROM MyGuests\";\n$result = $conn-&gt;query($sql);\nif ($result-&gt;num_rows &gt; 0) {\n\/\/ \u8f93\u51fa\u6bcf\u884c\u6570\u636e\nwhile($row = $result-&gt;fetch_assoc()) {\necho \"id: \". $row[\"id\"]. \" - Name: \". $row[\"firstname\"]. \" \" .\n$row[\"lastname\"]. \"&lt;br&gt;\";\n}\n} else {\necho \"0 results\";\n}\nmysqli_close($conn);\n?&gt;<\/code><\/pre>\n<p>\u4ee5\u4e0b\u5b9e\u4f8b\u8bfb\u53d6\u4e86 MyGuests \u8868\u7684\u6240\u6709\u8bb0\u5f55\u5e76\u663e\u793a\u5728 HTML \u8868\u683c\u4e2d\uff1a<\/p>\n<p>\u5b9e\u4f8b (PDO)<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\necho \"&lt;table style='border: solid 1px black;'&gt;\";\necho\n\"&lt;tr&gt;&lt;th&gt;Id&lt;\/th&gt;&lt;th&gt;Firstname&lt;\/th&gt;&lt;th&gt;Lastname&lt;\/th&gt;&lt;th&gt;Email&lt;\/th&gt;&lt;th&gt;Reg\ndate&lt;\/th&gt;&lt;\/tr&gt;\";\nclass TableRows extends RecursiveIteratorIterator {\nfunction __construct($it) {\nparent::__construct($it, self::LEAVES_ONLY);\n}\nfunction current() {\nreturn \"&lt;td style='width: 150px; border: 1px solid black;'&gt;\" .\nparent::current(). \"&lt;\/td&gt;\";\n}\nfunction beginChildren() {\necho \"&lt;tr&gt;\";\n}\nfunction endChildren() {\necho \"&lt;\/tr&gt;\" . \"n\";\n}\n}\n$servername = \"localhost\";\n$username = \"username\";\n$password = \"password\";\n$dbname = \"myDBPDO\";\ntry {\n$conn = new PDO(\"mysql:host=$servername;dbname=$dbname\", $username,\n$password);\n$conn-&gt;setAttribute(PDO::ATTR_ERRMODE,\nPDO::ERRMODE_EXCEPTION);\n$stmt = $conn-&gt;prepare(\"SELECT * FROM MyGuests\");\n$stmt-&gt;execute();\n\/\/ \u8bbe\u7f6e\u7ed3\u679c\u96c6\u4e3a\u5173\u8054\u6570\u7ec4\n$result = $stmt-&gt;setFetchMode(PDO::FETCH_ASSOC);\nforeach(new TableRows(new RecursiveArrayIterator($stmt-&gt;fetchAll())) as\n$k=&gt;$v) {\necho $v;\n}\n$dsn = null;\n}\ncatch(PDOException $e)\n{\necho \"Error: \" . $e-&gt;getMessage();\n}\n$conn = null;\necho \"&lt;\/table&gt;\";\n?&gt;\nPHP MySQL Where \u5b50\u53e5<\/code><\/pre>\n<p>\u901a\u8fc7\u4e0a\u4e00\u8282\u7684\u5185\u5bb9\uff0c\u4f60\u5df2\u7ecf\u53ef\u4ee5\u4f7f\u7528 MySQL \u7684 SELECT \u547d\u4ee4\u4ece\u6570\u636e\u8868\u4e2d\u83b7\u53d6\u6570\u636e\uff0c\u672c\u8282\u6211\u4eec\u53ef\u4ee5\u7528 WHERE \u547d\u4ee4\u6765\u7b5b\u9009\u51fa\u6ee1\u8db3\u6761\u4ef6\u7684\u7ed3\u679c\u3002<\/p>\n<p>WHERE \u5b50\u53e5\u7528\u4e8e\u8fc7\u6ee4\u8bb0\u5f55\u3002<\/p>\n<p>WHERE \u5b50\u53e5<\/p>\n<p>WHERE \u5b50\u53e5\u7528\u4e8e\u63d0\u53d6\u6ee1\u8db3\u6307\u5b9a\u6807\u51c6\u7684\u7684\u8bb0\u5f55\u3002<\/p>\n<p>\u8bed\u6cd5<\/p>\n<p>SELECT column_name(s)<\/p>\n<p>FROM table_name<\/p>\n<p>WHERE column_name operator value<\/p>\n<p>\u5982\u9700\u5b66\u4e60\u66f4\u591a\u5173\u4e8e SQL \u7684\u77e5\u8bc6\uff0c\u8bf7\u8bbf\u95ee\u6211\u4eec\u7684 SQL \u6559\u7a0b\u3002<\/p>\n<p>\u4e3a\u4e86\u8ba9 PHP \u6267\u884c\u4e0a\u9762\u7684\u8bed\u53e5\uff0c\u6211\u4eec\u5fc5\u987b\u4f7f\u7528 mysqli_query() \u51fd\u6570\u3002\u8be5\u51fd\u6570\u7528\u4e8e\u5411 MySQL \u8fde\u63a5\u53d1\u9001\u67e5\u8be2\u6216\u547d\u4ee4\u3002<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<p>\u4e0b\u9762\u7684\u5b9e\u4f8b\u5c06\u4ece &quot;Persons&quot; \u8868\u4e2d\u9009\u53d6\u6240\u6709 FirstName=&#8217;Peter&#8217; \u7684\u884c\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$con=mysqli_connect(\"example.com\",\"peter\",\"abc123\",\"my_db\");\n\/\/ Check connection\nif (mysqli_connect_errno())\n{\necho \"Failed to connect to MySQL: \" . mysqli_connect_error();\n}\n$result = mysqli_query($con,\"SELECT * FROM Persons\nWHERE FirstName='Peter'\");\nwhile($row = mysqli_fetch_array($result))\n{\necho $row['FirstName'] . \" \" . $row['LastName'];\necho \"&lt;br&gt;\";\n}\n?&gt;<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4ee3\u7801\u5c06\u8f93\u51fa\uff1a<\/p>\n<p>Peter Griffin<\/p>\n<p>\u5728\u4e0b\u4e00\u8282\u5185\u5bb9\u4e2d\uff0c\u6211\u4eec\u4f1a\u8bb2\u89e3\u5982\u4f55\u5bf9\u7b5b\u9009\u51fa\u6765\u7684\u8bb0\u5f55\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>PHP MySQL Order By \u5173\u952e\u8bcd<\/p>\n<p>\u4f60\u53ef\u4ee5\u5bf9 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u8bb0\u5f55\u96c6\u8fdb\u884c\u6392\u5e8f\uff0c\u5177\u4f53\u8bf7\u9605\u8bfb\u672c\u8282\u5185\u5bb9\u3002<\/p>\n<p>ORDER BY \u5173\u952e\u8bcd\u7528\u4e8e\u5bf9\u8bb0\u5f55\u96c6\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>ORDER BY \u5173\u952e\u8bcd<\/p>\n<p>ORDER BY \u5173\u952e\u8bcd\u7528\u4e8e\u5bf9\u8bb0\u5f55\u96c6\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>ORDER BY \u5173\u952e\u8bcd\u9ed8\u8ba4\u5bf9\u8bb0\u5f55\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\u3002<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u964d\u5e8f\u6392\u5e8f\uff0c\u8bf7\u4f7f\u7528 DESC \u5173\u952e\u5b57\u3002<\/p>\n<p>\u8bed\u6cd5<\/p>\n<p>SELECT column_name(s)<\/p>\n<p>FROM table_name<\/p>\n<p>ORDER BY column_name(s) ASC|DESC<\/p>\n<p>\u5982\u9700\u5b66\u4e60\u66f4\u591a\u5173\u4e8e SQL \u7684\u77e5\u8bc6\uff0c\u8bf7\u8bbf\u95ee\u6211\u4eec\u7684 SQL \u6559\u7a0b\u3002<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<p>\u4e0b\u9762\u7684\u5b9e\u4f8b\u9009\u53d6 &quot;Persons&quot; \u8868\u4e2d\u5b58\u50a8\u7684\u6240\u6709\u6570\u636e\uff0c\u5e76\u6839\u636e &quot;Age&quot; \u5217\u5bf9\u7ed3\u679c\u8fdb\u884c<\/p>\n<p>\u6392\u5e8f\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$con=mysqli_connect(\"example.com\",\"peter\",\"abc123\",\"my_db\");\n\/\/ Check connection\nif (mysqli_connect_errno())\n{\necho \"Failed to connect to MySQL: \" . mysqli_connect_error();\n}\n$result = mysqli_query($con,\"SELECT * FROM Persons ORDER BY age\");\nwhile($row = mysqli_fetch_array($result))\n{\necho $row['FirstName'];\necho \" \" . $row['LastName'];\necho \" \" . $row['Age'];\necho \"&lt;br&gt;\";\n}\nmysqli_close($con);\n?&gt;<\/code><\/pre>\n<p>\u4ee5\u4e0a\u7ed3\u679c\u5c06\u8f93\u51fa\uff1a<\/p>\n<p>Glenn Quagmire 33<\/p>\n<p>Peter Griffin 35<\/p>\n<p>\u6839\u636e\u4e24\u5217\u8fdb\u884c\u6392\u5e8f<\/p>\n<p>\u53ef\u4ee5\u6839\u636e\u591a\u4e2a\u5217\u8fdb\u884c\u6392\u5e8f\u3002\u5f53\u6309\u7167\u591a\u4e2a\u5217\u8fdb\u884c\u6392\u5e8f\u65f6\uff0c\u53ea\u6709\u7b2c\u4e00\u5217\u7684\u503c\u76f8\u540c\u65f6\u624d<\/p>\n<p>\u4f7f\u7528\u7b2c\u4e8c\u5217\uff1a<\/p>\n<p>SELECT column_name(s)<\/p>\n<p>FROM table_name<\/p>\n<p>ORDER BY column1, column2<\/p>\n<p>PHP MySQL Update<\/p>\n<p>\u5bf9\u4e8e MySQL \u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u66f4\u65b0\uff01<\/p>\n<p>UPDATE \u8bed\u53e5\u7528\u4e8e\u4e2d\u4fee\u6539\u6570\u636e\u5e93\u8868\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<p>\u66f4\u65b0\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e<\/p>\n<p>UPDATE \u8bed\u53e5\u7528\u4e8e\u66f4\u65b0\u6570\u636e\u5e93\u8868\u4e2d\u5df2\u5b58\u5728\u7684\u8bb0\u5f55\u3002<\/p>\n<p>\u8bed\u6cd5<\/p>\n<p>UPDATE table_name<\/p>\n<p>SET column1=value, column2=value2,&#8230;<\/p>\n<p>WHERE some_column=some_value<\/p>\n<p>\u6ce8\u91ca\uff1a\u8bf7\u6ce8\u610f UPDATE \u8bed\u6cd5\u4e2d\u7684 WHERE \u5b50\u53e5\u3002WHERE \u5b50\u53e5\u89c4\u5b9a\u4e86\u54ea\u4e9b\u8bb0<\/p>\n<p>\u5f55\u9700\u8981\u66f4\u65b0\u3002\u5982\u679c\u60a8\u60f3\u7701\u53bb WHERE \u5b50\u53e5\uff0c\u6240\u6709\u7684\u8bb0\u5f55\u90fd\u4f1a\u88ab\u66f4\u65b0\uff01<\/p>\n<p>\u5982\u9700\u5b66\u4e60\u66f4\u591a\u5173\u4e8e SQL \u7684\u77e5\u8bc6\uff0c\u8bf7\u8bbf\u95ee\u6211\u4eec\u7684 SQL \u6559\u7a0b\u3002<\/p>\n<p>\u4e3a\u4e86\u8ba9 PHP \u6267\u884c\u4e0a\u9762\u7684\u8bed\u53e5\uff0c\u6211\u4eec\u5fc5\u987b\u4f7f\u7528 mysqli_query() \u51fd\u6570\u3002\u8be5\u51fd\u6570\u7528\u4e8e<\/p>\n<p>\u5411 MySQL \u8fde\u63a5\u53d1\u9001\u67e5\u8be2\u6216\u547d\u4ee4\u3002<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u7684\u524d\u9762\u7ae0\u8282\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a &quot;Persons&quot; \u7684\u8868\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>FirstName LastName Age<\/p>\n<p>Peter Griffin 35<\/p>\n<p>Glenn Quagmire 33<\/p>\n<p>\u4e0b\u9762\u7684\u4f8b\u5b50\u66f4\u65b0 &quot;Persons&quot; \u8868\u7684\u4e00\u4e9b\u6570\u636e\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$con=mysqli_connect(\"example.com\",\"peter\",\"abc123\",\"my_db\");\n\/\/ Check connection\nif (mysqli_connect_errno())\n{\necho \"Failed to connect to MySQL: \" . mysqli_connect_error();\n}\nmysqli_query($con,\"UPDATE Persons SET Age=36\nWHERE FirstName='Peter' AND LastName='Griffin'\");\nmysqli_close($con);\n?&gt;<\/code><\/pre>\n<p>\u5728\u8fd9\u6b21\u66f4\u65b0\u540e\uff0c&quot;Persons&quot; \u8868\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>FirstName LastName Age<\/p>\n<p>Peter Griffin 36<\/p>\n<p>Glenn Quagmire 33<\/p>\n<p>PHP MySQL Delete<\/p>\n<p>\u5982\u679c\u4f60\u4e0d\u518d\u9700\u8981 MySQL \u6570\u636e\u5e93\u4e2d\u7684\u67d0\u6761\u8bb0\u5f55\u4e86\uff0c\u90a3\u4e48\u4f60\u4e5f\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5c06\u5176\u5220\u9664\uff01<\/p>\n<p>DELETE \u8bed\u53e5\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u8868\u4e2d\u5220\u9664\u884c\u3002<\/p>\n<p>\u5220\u9664\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e<\/p>\n<p>DELETE FROM \u8bed\u53e5\u7528\u4e8e\u4ece\u6570\u636e\u5e93\u8868\u4e2d\u5220\u9664\u8bb0\u5f55\u3002<\/p>\n<p>\u8bed\u6cd5<\/p>\n<p>DELETE FROM table_name<\/p>\n<p>WHERE some_column = some_value<\/p>\n<p>\u6ce8\u91ca\uff1a\u8bf7\u6ce8\u610f DELETE \u8bed\u6cd5\u4e2d\u7684 WHERE \u5b50\u53e5\u3002WHERE \u5b50\u53e5\u89c4\u5b9a\u4e86\u54ea\u4e9b\u8bb0<\/p>\n<p>\u5f55\u9700\u8981\u5220\u9664\u3002\u5982\u679c\u60a8\u60f3\u7701\u53bb WHERE \u5b50\u53e5\uff0c\u6240\u6709\u7684\u8bb0\u5f55\u90fd\u4f1a\u88ab\u5220\u9664\uff01<\/p>\n<p>\u5982\u9700\u5b66\u4e60\u66f4\u591a\u5173\u4e8e SQL \u7684\u77e5\u8bc6\uff0c\u8bf7\u8bbf\u95ee\u6211\u4eec\u7684 SQL \u6559\u7a0b\u3002<\/p>\n<p>\u4e3a\u4e86\u8ba9 PHP \u6267\u884c\u4e0a\u9762\u7684\u8bed\u53e5\uff0c\u6211\u4eec\u5fc5\u987b\u4f7f\u7528 mysqli_query() \u51fd\u6570\u3002\u8be5\u51fd\u6570\u7528\u4e8e<\/p>\n<p>\u5411 MySQL \u8fde\u63a5\u53d1\u9001\u67e5\u8be2\u6216\u547d\u4ee4\u3002<\/p>\n<p>\u5b9e\u4f8b<\/p>\n<p>\u8bf7\u770b\u4e0b\u9762\u7684 &quot;Persons&quot; \u8868\uff1a<\/p>\n<p>FirstName LastName Age<\/p>\n<p>Peter Griffin 35<\/p>\n<p>Glenn Quagmire 33<\/p>\n<p>\u4e0b\u9762\u7684\u5b9e\u4f8b\u5220\u9664 &quot;Persons&quot; \u8868\u4e2d\u6240\u6709 LastName=&#8217;Griffin&#8217; \u7684\u8bb0\u5f55\uff1a<\/p>\n<pre class=\"prettyprint linenums\" ><code class=\"language-sql\">&lt;?php\n$con=mysqli_connect(\"example.com\",\"peter\",\"abc123\",\"my_db\");\n\/\/ Check connection\nif (mysqli_connect_errno())\n{\necho \"Failed to connect to MySQL: \" . mysqli_connect_error();\n}\nmysqli_query($con,\"DELETE FROM Persons WHERE LastName='Griffin'\");\nmysqli_close($con);\n?&gt;<\/code><\/pre>\n<p>\u5728\u8fd9\u6b21\u5220\u9664\u540e\uff0c&quot;Persons&quot; \u8868\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>FirstName LastName Age<\/p>\n<p>Glenn Quagmire 33<\/p>\n<blockquote>\n<p>\u66f4\u65b0: 2025-04-23 11:56:08<br \/>\n\u539f\u6587: <a href=\"https:\/\/www.yuque.com\/yuhui.net\/network\/gezkx6dbirg0i5bk\">https:\/\/www.yuque.com\/yuhui.net\/network\/gezkx6dbirg0i5bk<\/a><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u57fa\u7840 \u6982\u8ff0 PHP\uff08\u5168\u79f0\uff1aPHP\uff1aHypertext Preprocessor\uff0c\u5373&quot;PHP\uff1a\u8d85\u6587\u672c\u9884\u5904\u7406\u5668&quot;\uff09\u662f\u4e00\u79cd \u901a\u7528\u5f00\u6e90\u811a\u672c\u8bed\u8a00\u3002 \u5728\u4e00\u4e2a php \u6587\u4ef6\u4e2d\u53ef\u4ee5\u5305\u62ec\u4ee5\u4e0b\u5185\u5bb9\uff1a PHP \u6587\u4ef6\u53ef\u5305\u542b\u6587\u672c\u3001HTML\u3001JavaScript \u4ee3\u7801\u548c PHP \u4ee3\u7801 PHP \u4ee3\u7801\u5728\u670d\u52a1\u5668\u4e0a\u6267\u884c\uff0c\u7ed3\u679c\u4ee5\u7eaf HTML \u5f62\u5f0f\u8fd4\u56de\u7ed9\u6d4f\u89c8\u5668 PHP \u6587\u4ef6\u7684\u9ed8\u8ba4\u6587\u4ef6\u6269\u5c55\u540d\u662f &quot;.ph [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[124,119,2],"tags":[6,7,12,18,22],"class_list":["post-804","post","type-post","status-publish","format-standard","hentry","category-qianzhizhishi","category-shentouceshijichu-network_sec","category-network_sec","tag-english","tag-study-c","tag-12","tag-18","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/posts\/804","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/comments?post=804"}],"version-history":[{"count":0,"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/posts\/804\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/media?parent=804"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/categories?post=804"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.youvii.site\/index.php\/wp-json\/wp\/v2\/tags?post=804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}