I wrote a script that uses PHP DOM. I'm parsing a webpage and accessing the elements through XPath.
Everything works fine except when it comes to getting a Node that will have either an tag or an tag.
What I want to do is basically:
if element tag is 'object' then < execute code here >
elseif element tag is 'iFrame' then < excecute alternative code>
Some Div Blocks will have: Code:
<div class="scenario1" >
<object src=xxxx... />
While others will have:
Code:
<div class="scenario2" >
<iFrame src=xxxx... />
This is the the only part left that's messing me up now. Any idea how do differentiate between an element type?It always displays a blank line if its an IFrame (I have an Xpath leading to the parent node that check for the object tag). I've tried checking if the node is empty/null then trying to search for a iFrame but it wasn't working for me and returned a blank line.
Use the tagName property, for example if $elem is a DOMElement:
if(strtolower($elem->tagName) == 'iframe'))
{
// it's an iframe
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With