Php preg匹配$variable中的数字

Php preg匹配$variable中的数字,php,regex,Php,Regex,假设我有: $id = "bla bla 123 number/4567''' "; 然后,我想添加一个preg_匹配,只过滤数字4567。$id中唯一稳定的东西是number/xxxx,所以当它找到这个结构number/xxxx或number/xxxxxxxx时(不管有多少个数字,把这些数字放在一个名为$a的变量中) 例如: input: $id = "bla bla 434323 123 number/456789abc "; In this case $a will take the

假设我有:

$id = "bla bla 123 number/4567''' ";
然后,我想添加一个preg_匹配,只过滤数字4567。$id中唯一稳定的东西是number/xxxx,所以当它找到这个结构number/xxxx或number/xxxxxxxx时(不管有多少个数字,把这些数字放在一个名为$a的变量中)

例如:

input: $id = "bla bla 434323 123  number/456789abc "; 
In this case $a will take the value 456789
但是,这种情况如何:

input: $id = "bla bla number/123 bla bla number/456 bla bla number/789xx ";
in this situation I want to get all matches like this:

$a will be 123
$b will be 456
$c will be 789
这不起作用:

<?php

$id = "bla bla number/123  number/456789abc "; 

function find_in_id_content($id)
{

if ( preg_match_all('#(?<=number/)\d+#', $str, $m ) ) {
    list($a, $b, $c, $d) = $m[0];
    printf("a=%s,b=%s,c=%s\n", $a, $b, $c);
}
}
echo $a;
?>

您可以使用:

if ( preg_match_all('#(?<=number/)\d+#', $str, $m ) ) {
    list($a, $b, $c, $d) = $m[0];
    printf("a=%s,b=%s,c=%s\n", $a, $b, $c);
}

使用以及它如何知道这个脚本只在$id内容中搜索?然后我需要像$a这样的变量来获取那个数字,我不知道如何处理那个数组以及如何将它放入简介$a$b$c…这捕获后面跟字符串
number/
。要将它们放入变量中,可以做:
$a=$m[0][0];$b=$m[0][1];$c=$m[0][2] 
或者,如果没有$a$b$c变量更简单的话,我应该用这些数字来回送一个列表,但是在这个地址www.example.com/file.php?x=(这个数字)
foreach($m[0]作为$number)回送“”;
@user3314333:检查更新的答案,了解如何从结果数组中填充
$a,$b,$c
if ( preg_match_all('#(?<=number/)\d+#', $str, $m ) ) {
    list($a, $b, $c, $d) = $m[0];
    printf("a=%s,b=%s,c=%s\n", $a, $b, $c);
}
a=123,b=456,c=789