You can use preg_match();
$str = '12PUM4';
$matches = array();
preg_match('/([0-9]+)([a-zA-z]+)(.*)/', $str, $matches);
print_r($matches);
Output
Array ( [0] => 12PUM4 [1] => 12 [2] => PUM [3] => 4 )
when you use this function it will split text and put matches in $matches
array
[0-9]+
- matches for numbers at least one or more
[a-zA-Z]+
are characters at least one or more
.*
is anything(almost)
()
- is used as subpattern which is put into $matches
array
More information of how to use preg_match can be found here
The solution with substr() under condtion you wrote that it has 12 digits, 3 characters and 1 or 2 digits in the end.
$str = '12PUM4';
$matches = array( 0 => substr($str,0, 2), 1 => substr($str, 2, 3) , 2 => substr($str, 5, strlen($str)>6 ? 2 : 1));
print_r($matches);
Output
Array ( [0] => 12 [1] => PUM [2] => 4 )