我试图学习如何从php页面中获取数据,我可以看到如何获取标签之间的所有内容,但有没有办法获取标签内的标签内容?是否可以嵌套preg_match?
在下面的html中,我将如何访问其中一个粗体跨度的内容,例如第二个?
<html>
<div class="padding10">
<span class="bold"></span>
<span class="bold"></span>
<span class="bold"></span>
<span class="bold"></span>
</div>
</html>
我尝试以下,这让我获得padding10 div的内容,但我不知道如何去任何进一步得到了大胆的跨越。我试过的所有东西都不起作用。
//gets all
$file_string = file_get_contents('http://www.test.com/index.html');
//gets all in padding10 div
preg_match('/<div class="padding10">(.*)<\/div>/si', $file_string, $padding_10);
//gets all bold spans on padding10 div??
preg_match_all('/<span class="bold">(.*)<\/span>/i', $padding_10[1], $spans_10);
我开始从我读什么,这是可能是想了解这个错误的或低效的方式,但任何帮助将是巨大的实现。谢谢。
http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – 2012-02-23 03:19:35
这应该让你开始:http://stackoverflow.com/questions/1898905/recursive-regular-expression-to-process-nested-strings-enclosed-by-and – yoda 2012-02-23 03:19:43
[你尝试过一个HTML解析器吗?](http://stackoverflow.com/questions/1732348/regex-match -open-tags-except-xhtml-self-contained-tags/1732454#1732454) – deceze 2012-02-23 03:19:51