{"id":3267,"date":"2018-03-27T15:04:30","date_gmt":"2018-03-27T07:04:30","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=3267"},"modified":"2018-03-27T15:04:30","modified_gmt":"2018-03-27T07:04:30","slug":"php-%e6%95%b0%e7%bb%84%e5%92%8c%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%ba%92%e7%9b%b8%e8%bd%ac%e6%8d%a2%e5%ae%9e%e7%8e%b0%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/jishu\/chengxujiaoben\/php\/php-%e6%95%b0%e7%bb%84%e5%92%8c%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%ba%92%e7%9b%b8%e8%bd%ac%e6%8d%a2%e5%ae%9e%e7%8e%b0%e6%96%b9%e6%b3%95\/","title":{"rendered":"PHP \u6570\u7ec4\u548c\u5b57\u7b26\u4e32\u4e92\u76f8\u8f6c\u6362\u5b9e\u73b0\u65b9\u6cd5"},"content":{"rendered":"<div class=\"codetitle\">PHP \u4e2d\u7531\u4e8e\u6570\u7ec4\u548c\u5b57\u7b26\u4e32\u8fd9\u4e24\u79cd\u53d8\u91cf\u7c7b\u578b\u662f\u5982\u6b64\u5e38\u7528\uff0c\u4ee5\u81f3\u4e8e PHP \u5177\u6709\u4e24\u4e2a\u51fd\u6570\uff0c\u53ef\u4ee5\u5728\u5b57\u7b26\u4e32\u548c\u6570\u7ec4\u4e4b\u95f4\u4e92\u76f8\u8fdb\u884c\u8f6c\u6362<\/div>\n<div class=\"codetitle\"><\/div>\n<div class=\"codetitle\">\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code4148\" class=\"codebody\">\n$array=explode(separator,$string);<br \/>\n$string=implode(glue,$array);<\/div>\n<p>\u4f7f\u7528\u548c\u7406\u89e3\u8fd9\u4e24\u4e2a\u51fd\u6570\u7684\u5173\u952e\u4e4b\u5904\u662f\u5206\u9694\u7b26\uff08separator\uff09\u548c\u80f6\u5408\u7b26\uff08glue\uff09\u5173\u7cfb\u3002\u5f53\u628a\u4e00\u4e2a\u6570\u7ec4\u8f6c\u6362\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u65f6\uff0c\u5c06\u4f1a\u8bbe\u7f6e\u80f6\u5408\u7b26\u2014\u2014\u5c06\u88ab\u63d2\u5165\u5230\u751f\u6210\u5b57\u7b26\u4e32\u4e2d\u7684\u6570\u7ec4\u503c\u4e4b\u95f4\u7684\u5b57\u7b26\u6216\u4ee3\u7801\u3002<\/p>\n<p>\u76f8\u53cd\uff0c\u5f53\u628a\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u7ec4\u65f6\uff0c\u8981\u6307\u5b9a\u5206\u9694\u7b26\uff0c\u5b83\u7528\u4e8e\u6807\u8bb0\u4ec0\u4e48\u5e94\u8be5\u53d8\u6210\u72ec\u7acb\u6570\u7ec4\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u4ee5\u5b57\u7b26\u4e32\u5f00\u59cb\uff1a<\/p>\n<p>$s1=&#8217;Mon-Tue-Wed-Thu-Fri&#8217;;<br \/>\n$days_array=explode(&#8216;-&#8216;,$s1);<br \/>\n$days_array \u53d8\u91cf\u73b0\u5728\u662f\u4e00\u4e2a\u67095\u4e2a\u5143\u7d20\u7684\u6570\u7ec4\uff0c\u5176\u5143\u7d20 Mon \u7684\u7d22\u5f15\u4e3a0\uff0cTue \u7684\u7d22\u5f15\u4e3a1\uff0c\u7b49\u7b49\u3002<br \/>\n$s2=implode(&#8216;,&#8217;,$days_array);<br \/>\n$s2<br \/>\n\u53d8\u91cf\u73b0\u5728\u662f\u4e00\u4e2a\u7528\u9017\u53f7\u5206\u9694\u7684\u4e00\u4e2a\u661f\u671f\u4e2d\u5404\u5929\u7684\u5217\u8868\uff1aMon,Tue,Wed,Thu,Fri<\/p>\n<p><strong>\u4f8b\u5b50 1. explode() \u793a\u4f8b<\/p>\n<p><\/strong><\/p>\n<div class=\"codetitle\"><a id=\"copybut95862\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code95862\" class=\"codebody\">\n&lt;?php<br \/>\n\/\/ \u793a\u4f8b 1<br \/>\n$pizza = &#8220;piece1 piece2 piece3 piece4 piece5 piece6&#8243;;<br \/>\n$pieces = explode(&#8221; &#8220;, $pizza);<br \/>\necho $pieces[0]; \/\/ piece1<br \/>\necho $pieces[1]; \/\/ piece2<br \/>\n\/\/ \u793a\u4f8b 2<br \/>\n$data = &#8220;foo:*:1023:1000::\/home\/foo:\/bin\/sh&#8221;;<br \/>\nlist($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(&#8220;:&#8221;, $data);<br \/>\necho $user; \/\/ foo<br \/>\necho $pass; \/\/ *<br \/>\n?&gt;<\/div>\n<p><strong>\u4f8b\u5b50 2. limit \u53c2\u6570\u793a\u4f8b<\/p>\n<p><\/strong><\/p>\n<div class=\"codetitle\"><a id=\"copybut73836\" class=\"copybut\"><\/a><u>\u590d\u5236\u4ee3\u7801<\/u>\u4ee3\u7801\u5982\u4e0b:<\/div>\n<div id=\"code73836\" class=\"codebody\">\n&lt;?php<br \/>\n$str = &#8216;one|two|three|four&#8217;;<br \/>\n\/\/ \u6b63\u6570\u7684 limit<br \/>\nprint_r(explode(&#8216;|&#8217;, $str, 2));<br \/>\n\/\/ \u8d1f\u6570\u7684 limit<br \/>\nprint_r(explode(&#8216;|&#8217;, $str, -1));<br \/>\n?&gt;<\/div>\n<p>\u4ee5\u4e0a\u793a\u4f8b\u5c06\u8f93\u51fa\uff1a<br \/>\nArray<br \/>\n(<br \/>\n[0] =&gt; one<br \/>\n[1] =&gt; two|three|four<br \/>\n)<br \/>\nArray<br \/>\n(<br \/>\n[0] =&gt; one<br \/>\n[1] =&gt; two<br \/>\n[2] =&gt; three<br \/>\n)<\/p>\n<p>\u6ce8: \u672c\u51fd\u6570\u53ef\u5b89\u5168\u7528\u4e8e\u4e8c\u8fdb\u5236\u5bf9\u8c61\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u4e2d\u7531\u4e8e\u6570\u7ec4\u548c\u5b57\u7b26\u4e32\u8fd9\u4e24\u79cd\u53d8\u91cf\u7c7b\u578b\u662f\u5982\u6b64\u5e38\u7528\uff0c\u4ee5\u81f3\u4e8e PHP \u5177\u6709\u4e24\u4e2a\u51fd\u6570\uff0c\u53ef\u4ee5\u5728\u5b57\u7b26\u4e32\u548c\u6570\u7ec4\u4e4b\u95f4\u4e92\u76f8\u8fdb &#8230; <a title=\"PHP \u6570\u7ec4\u548c\u5b57\u7b26\u4e32\u4e92\u76f8\u8f6c\u6362\u5b9e\u73b0\u65b9\u6cd5\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/jishu\/chengxujiaoben\/php\/php-%e6%95%b0%e7%bb%84%e5%92%8c%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%ba%92%e7%9b%b8%e8%bd%ac%e6%8d%a2%e5%ae%9e%e7%8e%b0%e6%96%b9%e6%b3%95\/\" aria-label=\"\u9605\u8bfb PHP \u6570\u7ec4\u548c\u5b57\u7b26\u4e32\u4e92\u76f8\u8f6c\u6362\u5b9e\u73b0\u65b9\u6cd5\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,11],"tags":[],"class_list":["post-3267","post","type-post","status-publish","format-standard","hentry","category-php","category-chengxujiaoben"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=3267"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3267\/revisions"}],"predecessor-version":[{"id":3268,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3267\/revisions\/3268"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=3267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=3267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=3267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}