I have not tested this code but it should work
PHP Code:
$string = '1978497748773434793'; $x = 7; $result = array(); $len = strlen($string);
for($pos1 = $pos2 = 0 ; $pos2 < $len; $pos2++) { if ($string{$pos2} == $x) { $pos2++; while($pos2 < $len && $string{$pos2} == $x) { $pos2++; } // $pos2 should now hold the position of the digit // after the last ocurance of $x in this segment $result[] = substr($string, $pos1, ($pos2-$pos1)); $pos1 = $pos2; } elseif($pos2 == $len-1) { // last digit, add to array evan if it's not $x $result[] = substr($string, $pos1, $len-$pos1); } }
Last edited by lizciz; 02-27-2009 at 08:15 PM..
|