使用php从正则表达式获取数组的结果


Result in the array fetched from a regular expression using php

我使用从正则表达式中获取了一些结果。

$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]索引中的值,如53060。请帮我找到那个。

PREG_OFFSET_CAPTURE

这将捕获偏移。这些数字告诉你字符串是在哪里找到的。

请先阅读手册。http://php.net/preg_match_all