我试图解析字符串中的标签,如下所示:
$string = "foo [cmd:tag1] bar [cmd:tag2] bla bla";
$pattern = "/\[cmd:(.+)\]/";
preg_match_all($pattern, $string, $matches, PREG_OFFSET_CAPTURE);
$rc = $matches[0];
foreach($rc as $tag)
{
print_r2($tag);
}
将返回:
Array
(
[0] => [cmd:tag1] bar [cmd:tag2]
[1] => 4
)
我的语法有什么问题,因为我期待以下结果:
Array
(
[0] => [cmd:tag1]
[1] => [cmd:tag2]
)
感谢
答案 0 :(得分:3)