PHP preg_match_all 重复出现模式
我正在尝试获取开放标签的匹配项。存在打开父标签(包括子标签)的问题。父标签被捕获,但忽略子标签。
前任。
</p>
<p>hello world</p>
<p><img
preg_match_all('/<(\/?[a-z]+)[^>]*\/?>/i', $trimmed_text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
将给出以下输出:
Array
(
[0] => Array
(
[0] => Array
(
[0] =>
[1] => 0
)
[1] => Array
(
[0] => /p
[1] => 1
)
)
[1] => Array
(
[0] => Array
(
[0] =>
[1] => 5 ) [1] => Array ( [0] => p [1] => 6 ) ) [2] => Array ( [0] => Array ( [0] =>
[1] => 19
)
[1] => Array
(
[0] => /p
[1] => 20
)
)
[3] => Array
(
[0] => Array
(
[0] =>
[1] => 24 ) [1] => Array ( [0] => p [1] => 25 ) ) )
父级中任何打开的标签是否有可能拥有子集数组?
I am trying to grab a match of open tags. Having an issue where a parent tag is opened including a child tag. The parent tag is captured but it ignores the children tags.
ex.
</p>
<p>hello world</p>
<p><img
preg_match_all('/<(\/?[a-z]+)[^>]*\/?>/i', $trimmed_text, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
would give the following output:
Array
(
[0] => Array
(
[0] => Array
(
[0] =>
[1] => 0
)
[1] => Array
(
[0] => /p
[1] => 1
)
)
[1] => Array
(
[0] => Array
(
[0] =>
[1] => 5 ) [1] => Array ( [0] => p [1] => 6 ) ) [2] => Array ( [0] => Array ( [0] =>
[1] => 19
)
[1] => Array
(
[0] => /p
[1] => 20
)
)
[3] => Array
(
[0] => Array
(
[0] =>
[1] => 24 ) [1] => Array ( [0] => p [1] => 25 ) ) )
Is it possible for any opened tags in a parent to have a subset array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你做得很困难,使用 PHP Simple HTML DOM Parser 来解析html,
例如:
you're doing it the hard way, use PHP Simple HTML DOM Parser to parse html,
ex: