3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "00 a 51 - a9b!_ æøå "; function splitNumsFromChars($haystack) { // yes this is litteraly what it does. the function name says it all. hahahahhaaha :)))) $numbers = ""; // init $chars = ""; // init preg_match_all("/(\d*)(\D*)/", $haystack, $matches); foreach($matches[1] as $match) { $numbers .= is_numeric($match) ? $match : ''; } foreach($matches[2] as $match) { $chars .= !is_numeric($match) ? $match : ''; } $return['numbers'] = $numbers; $return['chars'] = $chars; return $return; } var_dump(splitNumsFromChars($string));
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
array(2) { ["numbers"]=> string(5) "00519" ["chars"]=> string(20) " a - ab!_ æøå " }

preferences:
200.02 ms | 406 KiB | 366 Q