连续标记上的php preg_匹配

连续标记上的php preg_匹配,php,regex,preg-match,Php,Regex,Preg Match,我试图捕获apacheconf文件上的所有位置路径,以生成自动nginx模板 我正在读的文件是这样的 <Location /images/mobile> SetHandler modperl PerlOutputFilterHandler Apache2::AMFImageRendering </Location> <Location /images/otherroute> SetHandler modperl PerlOutp

我试图捕获apacheconf文件上的所有位置路径,以生成自动nginx模板

我正在读的文件是这样的

<Location /images/mobile>
    SetHandler modperl
    PerlOutputFilterHandler Apache2::AMFImageRendering
</Location>
<Location /images/otherroute>
    SetHandler modperl
    PerlOutputFilterHandler Apache2::AMFImageRendering
</Location>

SetHandler modperl
PerloutPutterHandler Apache2::AMFImageRendering
SetHandler modperl
PerloutPutterHandler Apache2::AMFImageRendering
我几乎让正则表达式与“位置”匹配组一起工作,我有以下内容

$file_str = file_get_contents($conf);
preg_match("/<Location\s+(?P<location>.*?)\s*>.*?Apache2::AMFImageRendering.*?<\/Location>/s", $file_str, $matches);
print_r($matches);
$file\u str=file\u get\u contents($conf);
preg_match(“/.*Apache2::AMFImageRendering.*?/s”,$file_str,$matches);
打印(匹配项);
问题是这只获取$matches['location']中的第一个位置“/images/mobile”

是否仍然可以匹配所有位置,而不拆分字符串或使用带偏移量的preg_匹配

谢谢你要找的人。这是PHP对正规正则表达式的
/g
修饰符的回答。传递的第三个参数(
$matches
)现在将包含一个全局匹配集数组

$file_str = file_get_contents($conf);
preg_match_all("/<Location\s+(?P<location>.*?)\s*>.*?Apache2::AMFImageRendering.*?<\/Location>/s", $file_str, $matches);

print_r($matches);
// Array (
//   [0] => Array
//     (
//       [0] => SetHandler modperl PerlOutputFilterHandler Apache2::AMFImageRendering
//       [1] => SetHandler modperl PerlOutputFilterHandler Apache2::AMFImageRendering
//     )
//   [location] => Array 
//     (
//       [0] => /images/mobile
//       [1] => /images/otherroute
//     )
//   [1] => Array
//     (
//       [0] => /images/mobile
//       [1] => /images/otherroute
//     )
//  )
$file\u str=file\u get\u contents($conf);
preg_match_all(“/.*Apache2::amfimagerrendering.*.?/s”,$file_str,$matches);
打印(匹配项);
//排列(
//[0]=>阵列
//     (
//[0]=>SetHandler modperl PerloutPutterHandler Apache2::AMFImageRendering
//[1]=>SetHandler modperl PerloutPutterHandler Apache2::AMFImageRendering
//     )
//[位置]=>阵列
//     (
//[0]=>/images/mobile
//[1]=>/images/otherroute
//     )
//[1]=>阵列
//     (
//[0]=>/images/mobile
//[1]=>/images/otherroute
//     )
//  )

将参数3设置为全局匹配数组。@SamSullivan谢谢!,这很好用,你能把它作为一个答案贴出来让我接受吗