我使用。
从正则表达式中获取了一些结果$res = "there are many restaurants in the city. Restaurants like xyz,abc. one restaurant like.....";
$pattern = '/restaurants?/i';
preg_match_all($pattern, substr($res,10), $matches, PREG_OFFSET_CAPTURE);
print_r($matches[0]);
对于这个正则表达式,我的输出是
Array
(
[0] => Array
(
[0] => restaurants
[1] => 5
)
[1] => Array
(
[0] => Restaurants
[1] => 30
)
[2] => Array
(
[0] => restaurant
[1] => 60
)
)
在[0]索引中,我找到了匹配的字符串。但是,我不知道{1}索引中的值如5
,30
,60
。请帮我找到。
答案 0 :(得分:2)