我想從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