我正在尝试从 html 获取子节点的值。
我尝试了什么: -
$data = $dom->getElementById($identifier);
$node = $data->childNodes;
foreach($node as $node)
{
echo $node->nodeName;
echo $node->nodeValue;
}
}
我能够获取所有子节点值,即使子标签没有值我得到一个空字符串。
如果标签具有适当的值,有什么方法可以获取值???
更新:-
我的html数据:-
<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..