Home >php教程 >php手册 >解读PHP函数explode()的具体使用方法

解读PHP函数explode()的具体使用方法

WBOY
WBOYOriginal
2016-06-13 11:07:171207browse

目前PHP函数explode()把字符串分割为数组
explode(separator,string,limit)
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的最大数目。

PHP函数explode()例子
 

<ol class="dp-xml">
<li class="alt"><span><span class="tag"></span><span class="tag-name">php</span><span> </span></span></li>
<li>
<span>$</span><span class="attribute">str</span><span> = </span><span class="attribute-value">"Hello world. It's a beautiful day."</span><span>;  </span>
</li>
<li class="alt"><span>print_r (explode(" ",$str));  </span></li>
<li>
<span class="tag">?></span><span> </span>
</li>
</ol>

输出:
 

<ol class="dp-xml">
<li class="alt"><span><span>Array  </span></span></li>
<li><span>(  </span></li>
<li class="alt">
<span>[0] =</span><span class="tag">></span><span> Hello  </span>
</li>
<li>
<span>[1] =</span><span class="tag">></span><span> world.  </span>
</li>
<li class="alt">
<span>[2] =</span><span class="tag">></span><span> It's  </span>
</li>
<li>
<span>[3] =</span><span class="tag">></span><span> a  </span>
</li>
<li class="alt">
<span>[4] =</span><span class="tag">></span><span> beautiful  </span>
</li>
<li>
<span>[5] =</span><span class="tag">></span><span> day.  </span>
</li>
<li class="alt"><span>) </span></li>
</ol>

以上代码示例就是PHP函数explode()的具体使用。


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn