keep only numbers in a string php code example Example: php keep only numbers in string $str = preg_replace('/[^0-9.]+/', '', $str);