PHP 搜索嵌套的html元素
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP 搜索嵌套的html元素相关的知识,希望对你有一定的参考价值。
// dummy html
$html = '<div id="a1"><div id="a1-1"></div><div id="a1-2"></div></div><div id="a2"></div>';
// the magic
preg_match_all('/<([a-z]+)[^>]*>(?:(?:(?!<\1[^>]*>|<\/\1>).|(?R))*)<\/\1>/si', $html, $matches);
// print result
printf('<pre>%s</pre>', str_replace('<', '&lt;', print_r($matches, true)));
以上是关于PHP 搜索嵌套的html元素的主要内容,如果未能解决你的问题,请参考以下文章