1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?php
$str = "p, B7, B8, B9 , B10 , B11 || || || || || || A9 , A25 |8| |17|";
//$str = "p,B5,B7 |1| |2,3,4| |5| A5 , A11 |4| |5|";
$len = strlen($str);
$nbComma = 0;
$nbPipe = 0;
$nbValues = 0;
for($i = 0; $i < $len; ++$i) {
$char = $str[$i];
if ($char === '|') {
if ($nbPipe === 0) {
$nbValues = ($nbComma + 1) * 2;
}
if (++$nbPipe === $nbValues) {
$toKeep = trim(substr($str, $i + 1));
break;
}
}
else
if ($char === ',') {
++$nbComma;
}
}
echo $toKeep;
?> |
Partager