function getNumber($string) { preg_match_all('/\d+/', $string, $matches); return (int)implode('', $matches[0]); }This code uses regular expressions to find all numeric characters in the string and then concatenates them into a single numeric string. Finally, the string is cast to an integer and returned. This function does not require any additional package library as it is a built-in function in PHP.