Preg_match_all也返回初始值

问题描述:

如果我提出的正则表达式,并通过阵列$content它:Preg_match_all也返回初始值

preg_match_all(/([0-9]+)\/([0-9]+)/, $content, $matches); 

哪里$content是数组:

Name Address 77/88 Country 
Name Address 71/90 Country 
Name Address 72/43 Country 
Name Address 76/55 Country 
Name Country 
Name Address 

它将返回$matches

array(4) { 
    [0]=> 
    string(5) "77/88" 
    [1]=> 
    string(5) "71/90" 
    [2]=> 
    string(5) "72/43" 
    [3]=> 
    string(5) "76/55" 
    } 

但我能不知何故最初的数组$content瓦尔你也有匹配的值吗?

+0

预期结果是什么? – Toto

$content将需要为preg_match_all()的字符串:

preg_match_all('/^.*?([0-9]+)\/([0-9]+).*$/m', $content, $matches); 

产量:

Array 
(
    [0] => Array 
     (
      [0] => Name Address 77/88 Country 
      [1] => Name Address 71/90 Country 
      [2] => Name Address 72/43 Country 
      [3] => Name Address 76/55 Country 
     ) 

    [1] => Array 
     (
      [0] => 77 
      [1] => 71 
      [2] => 72 
      [3] => 76 
     ) 

    [2] => Array 
     (
      [0] => 88 
      [1] => 90 
      [2] => 43 
      [3] => 55 
     ) 
) 

如果$content真的是一个数组:

$matches = preg_grep('/([0-9]+)\/([0-9]+)/', $content); 

产量:

Array 
(
    [0] => Name Address 77/88 Country 
    [1] => Name Address 71/90 Country 
    [2] => Name Address 72/43 Country 
    [3] => Name Address 76/55 Country 
)