Xpath nodeValue / textContent无法看到< BR>标签 [英] Xpath nodeValue/textContent unable to see <BR> tag
本文介绍了Xpath nodeValue / textContent无法看到< BR>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML如下:
< a href =#> ABC< BR> DEF< / a> ;
但是,nodeValue和textContent属性都显示 显示或解析ABCDEF$ c
< BR>
?
解决方案
也许这会帮助你: DOMNode :: C14N
它会返回节点的HTML。
<?php
$ a ='< a href =#> ABC< BR> DEF< / a>';
$ doc = new DOMDocument();
@ $ doc-> loadHTML($ a);
$ finder = new DomXPath($ doc);
$ nodes = $ finder-> query(// a);
foreach($ nodes为$ node){
var_dump($ node-> c14n());
}
HTML is as follows:
<a href="#">ABC<BR>DEF</a>
However, both nodeValue and textContent attributes show "ABCDEF"
as the value.
Any way to show or parse the <BR>
?
解决方案
Maybe this'll help you: DOMNode::C14N
It'll return the HTML of the node.
<?php
$a = '<a href="#">ABC<BR>DEF</a>';
$doc = new DOMDocument();
@$doc->loadHTML($a);
$finder = new DomXPath($doc);
$nodes = $finder->query("//a");
foreach ($nodes as $node) {
var_dump($node->c14n());
}
这篇关于Xpath nodeValue / textContent无法看到< BR>标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文