{"id":27502,"date":"2024-11-24T10:26:15","date_gmt":"2024-11-24T02:26:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27502\/"},"modified":"2024-11-24T10:26:15","modified_gmt":"2024-11-24T02:26:15","slug":"php%e6%80%8e%e4%b9%88%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%88%86%e5%89%b2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27502\/","title":{"rendered":"php\u600e\u4e48\u5c06\u5b57\u7b26\u4e32\u5206\u5272"},"content":{"rendered":"<blockquote><p>\n  php \u4e2d\u5b57\u7b26\u4e32\u5206\u5272\u6709\u4e09\u79cd\u5e38\u89c1\u65b9\u6cd5\uff1a\u4f7f\u7528 explode() \u51fd\u6570\u6309\u5206\u9694\u7b26\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a\u6570\u7ec4\uff1b\u4f7f\u7528 str_split() \u51fd\u6570\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a\u5b57\u7b26\u6570\u7ec4\uff1b\u4f7f\u7528 preg_split() \u51fd\u6570\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/11\/2024111100311354984.jpg\" class=\"aligncenter\" title=\"php\u600e\u4e48\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u63d2\u56fe\" alt=\"php\u600e\u4e48\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP\u5b57\u7b26\u4e32\u5206\u5272<\/strong><\/p>\n<p>\u5728PHP\u4e2d\uff0c\u5b57\u7b26\u4e32\u53ef\u4ee5\u88ab\u5206\u5272\u6210\u66f4\u5c0f\u7684\u90e8\u5206\u3002\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u5b57\u7b26\u4e32\u5206\u5272\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u81ea\u8eab\u7684\u4f18\u52bf\u548c\u7f3a\u70b9\u3002<\/p>\n<p><strong>\u4f7f\u7528explode()\u51fd\u6570<\/strong><\/p>\n<p>explode()\u51fd\u6570\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u6570\u7ec4\uff0c\u6839\u636e\u6307\u5b9a\u7684\u5b57\u7b26\u4f5c\u4e3a\u5206\u9694\u7b26\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>explode(separator, string, limit)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>separator \u662f\u7528\u4e8e\u5206\u5272\u5b57\u7b26\u4e32\u7684\u5206\u9694\u7b26\u3002<\/li>\n<li>string \u662f\u8981\u5206\u5272\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<li>limit \u662f\u9650\u5236\u8fd4\u56de\u6570\u7ec4\u5143\u7d20\u6570\u91cf\u7684\u53ef\u9009\u53c2\u6570\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>$str = \"PHP, is, a, general-purpose, scripting, language\";\n$arr = explode(\",\", $str);\nprint_r($arr);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Array\n(\n    [0] =&gt; PHP\n    [1] =&gt; is\n    [2] =&gt; a\n    [3] =&gt; general-purpose\n    [4] =&gt; scripting\n    [5] =&gt; language\n)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528str_split()\u51fd\u6570<\/strong><\/p>\n<p>str_split()\u51fd\u6570\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u5b57\u7b26\u6570\u7ec4\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>str_split(string, length)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>string \u662f\u8981\u5206\u5272\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<li>length \u662f\u53ef\u9009\u53c2\u6570\uff0c\u6307\u5b9a\u6bcf\u4e2a\u5b57\u7b26\u7684\u957f\u5ea6\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>$str = \"PHP\";\n$arr = str_split($str);\nprint_r($arr);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Array\n(\n    [0] =&gt; P\n    [1] =&gt; H\n    [2] =&gt; P\n)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528preg_split()\u51fd\u6570<\/strong><\/p>\n<p>preg_split()\u51fd\u6570\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u6570\u7ec4\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>preg_split(pattern, string, limit, flags)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>pattern \u662f\u7528\u4e8e\u5206\u5272\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/li>\n<li>string \u662f\u8981\u5206\u5272\u7684\u5b57\u7b26\u4e32\u3002<\/li>\n<li>limit \u662f\u9650\u5236\u8fd4\u56de\u6570\u7ec4\u5143\u7d20\u6570\u91cf\u7684\u53ef\u9009\u53c2\u6570\u3002<\/li>\n<li>flags \u662f\u53ef\u9009\u53c2\u6570\uff0c\u6307\u5b9a\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u6807\u5fd7\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>$str = \"PHP is a general-purpose scripting language\";\n$arr = preg_split(\"\/s+\/\", $str);\nprint_r($arr);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Array\n(\n    [0] =&gt; PHP\n    [1] =&gt; is\n    [2] =&gt; a\n    [3] =&gt; general-purpose\n    [4] =&gt; scripting\n    [5] =&gt; language\n)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fphp\u600e\u4e48\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php \u4e2d\u5b57\u7b26\u4e32\u5206\u5272\u6709\u4e09\u79cd\u5e38\u89c1\u65b9\u6cd5\uff1a\u4f7f\u7528 explode() \u51fd\u6570\u6309\u5206\u9694\u7b26\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a\u6570\u7ec4\uff1b\u4f7f\u7528 str_split() \u51fd\u6570\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a\u5b57\u7b26\u6570\u7ec4\uff1b\u4f7f\u7528 preg_split() \u51fd\u6570\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5c06\u5b57\u7b26\u4e32\u5206\u5272\u4e3a\u6570\u7ec4\u3002 PHP\u5b57\u7b26\u4e32\u5206\u5272 \u5728PHP\u4e2d\uff0c\u5b57\u7b26\u4e32\u53ef\u4ee5\u88ab\u5206\u5272\u6210\u66f4\u5c0f\u7684\u90e8\u5206\u3002\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5b9e\u73b0\u5b57\u7b26\u4e32\u5206\u5272\uff0c\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u81ea\u8eab\u7684\u4f18\u52bf\u548c\u7f3a\u70b9\u3002 \u4f7f\u7528explode()\u51fd\u6570 explode()\u51fd\u6570\u5c06\u5b57\u7b26\u4e32\u62c6\u5206\u4e3a\u6570\u7ec4\uff0c\u6839\u636e\u6307\u5b9a\u7684\u5b57\u7b26\u4f5c\u4e3a\u5206\u9694\u7b26\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b explode(separator, string, limit) \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a separator \u662f\u7528\u4e8e\u5206\u5272\u5b57\u7b26\u4e32\u7684\u5206\u9694\u7b26\u3002 string \u662f\u8981\u5206\u5272\u7684\u5b57\u7b26\u4e32\u3002 limit \u662f\u9650\u5236\u8fd4\u56de\u6570\u7ec4\u5143\u7d20\u6570\u91cf\u7684\u53ef\u9009\u53c2\u6570\u3002 \u4f8b\u5982\uff1a $str = &#8220;PHP, is, a, general-purpose, scripting, language&#8221;; $arr = explode(&#8220;,&#8221;, $str); print_r($arr); \u767b\u5f55\u540e\u590d\u5236 \u8f93\u51fa\uff1a Array ( [0] =&gt; PHP [1] =&gt; is [2] =&gt; a [3] =&gt; general-purpose [4] [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27502","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27502","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27502"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27502\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}