preg_match_all 仅 return 第一个索引为 0 而不是索引为 1 的数组

preg_match_all only return the first array with index 0 and not one with index 1

1。我正在尝试将来自的一些 ID 与 url 和 return 所有 ID 匹配。

代码如下

字符串是这样的

"gfdgfds.php?id=67f8d4fd6d4&gfddgfds.php?
id=67f8d4f6d4&gfddgfds.php?id=67f8d4f6d4&gfdsgfds.php?id=67f8d4f6fdd4&"

模式

$pattern = '/p?id=[0-9A-Za-z]*/';

代码

preg_match_all($pattern,$input,$matches);   
    //var_dump(count($matches));
     if( count($matches) > 0 ) {
         var_dump($matches);
        //return $matches[1];
     } else {
        die('No matches found.');    
    }

但是从上面我做 var_dump($matches) 我得到了。

array (size=1)
  0 => 

我期待得到

array (size=1)
      0 =>array()
      1 =>array() // So I can use this.  

我在这里遗漏了什么,谢谢。

2。另外,我希望 $pattern = "'/p?id=[0-9A-Za-z]*/'" 匹配 "php?id=value",而不仅仅是任何 id=value。

您可以使用 parse_url 函数而不是使用正则表达式,但不确切知道您的预期输出是什么而不是 preg_match_all 使用 preg_match 和以下正则表达式

(.php\?id=(\w+))

所以你的代码看起来像

preg_match("/(.php\?id=(\w+))/",$your_string,$matches);