我有以下代码来检索HTML文档中的所有超链接
我的问题是如何检索每个锚标记内的文本节点
(即使文本节点是子节点的子节点,如果锚节点的跨节点有文本节点)?
<?PHP
$content = "
<html>
<head>
<title>bar , this is an example</title>
</head>
<body>
<a href='aaa'><span>bbb</span></a>
</body>
</html>
";
$dom = new DOMDocument();
@$dom->loadHTML($content);
$xpath = new DOMXPath($dom);
$row = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $row->length; $i++) {
$anchor = $row->item($i);
$href = $anchor->getAttribute('href');
// I want the grab the text value which is inside the anchor
$text = //should have the value "bbb"
}
?>
由于
答案 0 :(得分:3)
答案 1 :(得分:0)