关于截取以逗号隔开的字符串位数解决办法

WBOY
Release: 2016-06-13 12:55:42
Original
991 people have browsed it

关于截取以逗号隔开的字符串位数

本帖最后由 liangcaijian 于 2013-01-18 16:06:09 编辑 字符串是:0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411,

注:把加粗的部分截取出来。。。

要实现的效果:48423,48425,48427,48419

截取的是以逗号隔开的字符,从第一个逗号到后面隔了三个逗号的字符截取出来。

具体怎么实现呢?求助,在线等。。

------解决方案--------------------
$s = '0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411,';<br />
<br />
echo preg_replace('/\d+,((?:\d+,){3}\d+).*/', '$1', $s);<br />
Copy after login

------解决方案--------------------
$string = "0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411,";<br />
 $ar=explode(',',$string);<br />
  $arr=array_slice($ar,1,4);<br />
  echo join(',',$arr);
Copy after login

------解决方案--------------------
<br />
	$str="0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411,";<br />
	function jiequ($str,$a,$b){<br />
		$ar=explode(",",$str);<br />
		for($i=$a;$i<$b;$i++){<br />
			$br[]=$ar[$i];<br />
		}<br />
		return implode(",",$br);<br />
	}<br />
	echo jiequ($str,1,5);//1和5表示截取第一个,和第5个,之间的数<br />
Copy after login
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template