Try this:
preg_split("/(?=[0-9])/", 'fujitsu30001');
Question
I'm using preg_split
to split a value. I need to store each value of the split into an array.
currently what is being passed in to the preg split is:
preg_split("/[0-9]/", fujitsu30001 , NULL , PREG_SPLIT_OFFSET_CAPTURE);
I need it to split on each number so it appears as:
[fujitsu, 3, 0, 0, 0, 1]
in an array, any help would be great on this matter.
Would it be better to use preg_match
?
Solution
OTHER TIPS
You should use matching instead of splitting:
preg_match_all('/[a-z]+|\d/i', 'fujitsu30001', $matches);
print_r($matches[0]);
The expression matches either:
This is repeated until it reaches the end of the subject.
I managed to do it via preg_split:
$regex= "#([0-9])#";
$string = 'fujitsu30001';
$array = preg_split($regex, $string, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
which split the string on hitting a number so it appeared as
fujitsu, 3, 0, 0, 0, 1