How can I check if a p
has a child node of iframe
with DOMDocument
?
For instance,
<p><iframe ....></p>
I want to print this only,
<iframe ....>
While,
<p>bla bla bal</p>
then do nothing or just print whatever inside the p,
<p>bla bla bal</p>
Or,
<p>bla bla <b>bal</b></p>
then do nothing or just print whatever inside the p,
<p>bla bla <b>bal</b></p>
my php,
$dom = new DOMDocument;
$dom->loadHTML($item_html);
if($dom->getElementsByTagName('p')->length > 1 )
{
...
}
else // if it is only a single paragraph... then do what I want above...
{
foreach ($dom->getElementsByTagName('p') as $node)
{
if ($node->hasChildNodes())
{
foreach( $dom->getElementsByTagName('iframe') as $iframe )
{
... something
}
}
else
{
...
}
}
}
is it possible?