Home >Backend Development >PHP Tutorial >preg_split 分割字符串的有关问题

preg_split 分割字符串的有关问题

WBOY
WBOYOriginal
2016-06-13 12:12:31896browse

preg_split 分割字符串的问题
请教大家一个问题,用preg_split 分割字符串,
需要按 "第X个",这样的方式分割,X为不固定的,这个正则该怎么写,我写的有问题
$s="第1个哈哈哈哈第2个啦啦啦啦第三个啦啦啦啦啦第四个大大大”

$a = preg_split('/第.+?个/', $s);

其实就是按照文档里的 ”第1个“,”第2个“,”第3个“,这种来分割
------解决思路----------------------

$s = '第1个哈哈哈哈第2个啦啦啦啦第三个啦啦啦啦啦第四个大大大';<br />$a = preg_split('/第(?:\d+<br><font color='#FF8000'>------解决思路----------------------</font><br>三<br><font color='#FF8000'>------解决思路----------------------</font><br>四)个/', $s);<br />print_r($a);<br />
Array<br />(<br />    [0] => <br />    [1] => 哈哈哈哈<br />    [2] => 啦啦啦啦第<br />    [3] => 啦啦啦啦啦第<br />    [4] => 大大大<br />)<br /><br />

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