PHP Question- Check if Element Node is Iframe or Object

Discussion in 'Programming/Html' started by mike41, Jun 10, 2013.

  1. mike41

    mike41 Guest

    Messages:
    1,208
    Likes Received:
    0
    GPU:
    Evga 560ti
    Hello all, 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 <iFrame> tag or an <Object> 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.
     
    Last edited: Jun 10, 2013
  2. mike41

    mike41 Guest

    Messages:
    1,208
    Likes Received:
    0
    GPU:
    Evga 560ti
    found it out:

    if(strtolower($elem->tagName) == 'iframe')){ }

    Use either the ->tagName or ->nodeName property
     

Share This Page