我正在尝试从字符串中获取数值。理想情况下,包含两个数字的数组。
我正在使用此PHP,但它似乎仅与第一个匹配,而不与第二个匹配。
$str = 'The address has changed from #1216640 to #1218908';
preg_match_all(
'/The address has changed from #(.+?) to #(.+?)/s',
$str,
$output,
PREG_SET_ORDER
);
print_r($output);
我想要的是一个返回1216640和1218908的数组
您可以使用以下内容,只需搜索#
字符串中的数字。
$string = 'The address has changed from #1216640 to #1218908';
preg_match_all('/#([0-9]+)/', $string, $matches);
print_r($matches[1]);
输出
Array
(
[0] => 1216640
[1] => 1218908
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句