About intercepting a comma-separated number of strings
This post was last edited by Liangcaijian on 2013-01-18 16:06:09
The string is: 0,
48423,48425,48427,48419, 48413,48415,48417,48418,48414,48416,48411,
Note: The bold part is truncated ...
Effects to achieve: 48423,48425,48427,48419
A comma-separated character is intercepted, from the first comma to the three comma-separated characters.
How to achieve it? Help, online, etc...
------Solution--------------------
$s = ' 0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411, ';
echo preg_replace ('/\d+, (?: \ D+,) {3}\d+). */', ' $ ', $s);
------Solution--------------------
$string = "0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411,";
$ar =explode (', ', $string);
$arr =array_slice ($ar, 1,4);
echo Join (', ', $arr);
------Solution--------------------
$str = "0,48423,48425,48427,48419,48413,48415,48417,48418,48414,48416,48411,";
function jiequ ($str, $a, $b) {
$ar =explode (",", $str);
for ($i = $a; $i < $b; $i + +) {
$BR []= $ar [$i];
}
Return implode (",", $BR);
}
Echo jiequ ($str, 1,5);//1 and 5 means intercept the first, and the 5th, the number between