How to filter child tags value of a <div>
and display just the parent inner texts? For example in this code :
include('simple_html_dom.php');
$htm='<div class="date">
<span class="title">post date <!-- or Anything --> :</span>
2103/04/07 13:06
</div>';
$html = str_get_html($htm);
$date = $html->find('.date ',0)->plaintext;
echo $date;
The result is :
post date : 2103/04/07 13:06
But I need :
2103/04/07 13:06
Is there any way to filter the <span>
values? I prefer to not use patterns in my case. Thank you
This is possibly not the cleanest solution, but it works:
$dateDiv = $html->find('.date', 0);
$textElems = $dateDiv->find('text');
$str = '';
foreach ($textElems as $subText) {
if ($subText->parent() === $dateDiv) {
$str .= $subText->plaintext;
}
}
echo $str;
It retrieves all text blocks and then removes all nodes which are not direct children of <div class="date">
.