关于截取以逗号隔开的字符串位数
本帖最后由 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 />
로그인 후 복사
------解决方案--------------------$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);
로그인 후 복사
------解决方案--------------------<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 />
로그인 후 복사