Extract numbers from a unicode string
function unicodeStrDigits($str) { $arr = array(); $sub = ''; for ($i = 0; $i < strlen($str); $i++) { if (is_numeric($str[$i])) { $sub .= $str[$i]; continue; } else { if ($sub) { array_push($arr, $sub); $sub = ''; } } } if ($sub) { array_push($arr, $sub); } return $arr; }
Other way:
$res = array(); $str = 'test 1234 555 2.7 string ..... 2.2 3.3'; $str = preg_replace("/[^0-9\.]/", " ", $str); $str = trim(preg_replace('/\s+/u', ' ', $str)); $arr = explode(' ', $str); for ($i = 0; $i < count($arr); $i++) { if (is_numeric($arr[$i])) { $res[] = $arr[$i]; } } print_r($res); //Array ( [0] => 1234 [1] => 555 [2] => 2.7 [3] => 2.2 [4] => 3.3 )