可以使用正则表达式来提取字符串中的数字,例如使用preg_match_all函数来匹配所有的数字:
$str = "Hello123World456";preg_match_all('/\d+/', $str, $matches);$numbers = $matches[0];print_r($numbers);输出结果:
Array( [0] => 123 [1] => 456)在上述代码中,使用正则表达式/\d+/匹配连续的数字,然后使用preg_match_all函数将所有匹配结果保存在$matches变量中。最后将提取到的数字打印出来。

