Home > php教程 > php手册 > PHP split()函数的使用方法详解

PHP split()函数的使用方法详解

WBOY
Release: 2016-06-13 11:08:02
Original
1737 people have browsed it

函数原型:array split (string $pattern, string $string [, int $limit])

PHP split()函数返回一个字符串数组,每个单元为$string经正则表达式$pattern作为边界分割出的子串。如果设定了$limit,则返回的数组最多包含$limit个单元。而其中最后一个单元包含了$string中剩余的所有部分。spliti是split的忽略大小版本。代码6.8是一个经常用到关于日期的示例。

PHP split()函数代码6.8 日期的拆分

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ?php   </span></span></span></li>
<li>
<span>$</span><span class="attribute">date</span><span> = </span><span class="attribute-value">"08/30/2006"</span><span>;  </span>
</li>
<li class="alt"><span>//分隔符可以是斜线,点,或横线  </span></li>
<li><span>list($month, $day, $year) = split <br>('[/.-]', $date);  </span></li>
<li class="alt"><span>//输出为另一种时间格式  </span></li>
<li>
<span>echo "Month: $month; Day: $day; Year: <br>$year</span><span class="tag"><span class="tag-name">br</span><span> </span><span class="tag">/></span><span>n";  </span></span>
</li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol>
Copy after login

希望通过以上这段PHP split()函数的代码示例,大家能够清晰的了解这个函数的具体含义。


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template