- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
function get_numerics ($str) {
preg_match_all('/\d{4}/', $str, $matches);
return $matches[0];
}
$one = 'Rotterdam 3012 BG';
$two = '3012BG';
$three = '30123 BG';
$four = 'Rotterdam';
print_r(get_numerics($one));
print_r(get_numerics($two));
print_r(get_numerics($three));
print_r(get_numerics($four));