(スペースなどではなく)実際のテキストまたは子要素ノードを含む要素のみを取得したい。
私は次のhtmlを試しました:
<p> </p>
<div> </div>
そして私はこれまでこのコードを試しました:
$dom = new DOMDocument;
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$i = 0;
while (is_object($html_synch = $dom->getElementsByTagName("body")->item($i))) {
foreach ($html_synch->childNodes as $node) {
if ($node->nodeName != "script" && $node->nodeName != "style" &&
XML_COMMENT_NODE != $node->nodeType):
get_children($node);
endif;
}
$i++;
}
そして、get_children関数で、このコードを使用して、空のノードまたはノードを
次のようにフィルタリングしています。
foreach ($node->childNodes as $child) :
if (trim($child->nodeValue) != ""):
echo $child->nodeValue; // it returns Â
echo $child->nodeName; // it returns #text
array_push($children_type, $child->nodeType);
endif;
endforeach;
print_r($children_type);
#text  and Array ( [0] => 3 )
だけ戻ります<p> </p>
。では、どうすればそれらをフィルタリングできますか?そして、#textがテキストの特別なノード名であることを私は知っています。