在简单HTML Dom中的注释之间进行解析 [英] Parse between comments in Simple HTML Dom
本文介绍了在简单HTML Dom中的注释之间进行解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用简单HTML Dom提取两个html注释之间的数据吗?
Can I fetch the data between two html comments using Simple HTML Dom ??
例如,请参见下面的代码:
For example, See the below code:
<!-- start of comment -->
<a href="link1.html" target="_blank">link1</a><br />
<a href="link2.html" target="_blank">link2</a><br />
<a href="link3.html" target="_blank">link3</a><br />
<a href="link4.html" target="_blank">link4</a><br />
<!-- end of comment-->
<a href="link5.html" target="_blank">link5</a><br />
<a href="link6.html" target="_blank">link6</a><br />
总共有六个链接,而在"和"标记中仅包含4个链接.
There are totally six links and only 4 links are enclosed within a "" and "" tags.
我只想获取评论标签之间的链接.
I just want to get the links between the comment tags.
推荐答案
尝试此代码
$dom = new DOMDocument();
$dom->loadHTML($html);
$elements = $dom->getElementsByTagName('a');
foreach ($elements as $child) {
echo $child->nodeValue;
}
这篇关于在简单HTML Dom中的注释之间进行解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文