我想从html中获取子节点的值。在html中获取子节点的值
我想什么: -
$data = $dom->getElementById($identifier);
$node = $data->childNodes;
foreach($node as $node)
{
echo $node->nodeName;
echo $node->nodeValue;
}
}
我能够得到所有的childNodes值,即使childtag没有值 我得到一个空字符串。
如果标签有合适的值,有没有办法获取值?
更新: -
我htmldata: -
<div id="myid"> //I give this id as input
<h1> Some data 1</h1>
<script type=".."> google adsense details </script>
<p class="some class"> </p>
<div class="some class1"></div>
<h2>data2</h2>
<p>SOme more data...blah blah..</p>
</div>
我想要的输出: -
Some data 1
data2
SOme more data...blah blah..
什么我得到: -
Some data 1
googleadsense details//i am getting values inside script as well
//blanc data which includes many spaces of tag p
//blanc data which includes many spaces of tag div
data2
SOme more data...blah blah..
'(如$ $节点节点)'或'($数据作为$节点)'?? – 2013-03-13 05:49:04
我改变了代码... – 2013-03-13 05:50:01
表决了什么? – 2013-03-13 05:51:12