Search code examples
phphtml-parsingphpquery

Discover what element is using phpQuery()


I am using phpQuery to parse every single element of HTML files, what I do is something like this:

foreach (pq('body')->children() as $children) {
    // do some code here
}

However, I need to know which element is being parsed (table, div, p...).

How can I do this?


Solution

  • Ok, I dit it. As phpQuery is based on DOMDocument I just had to use the attribute nodeName, like this:

    foreach (pq('body')->children() as $children) {
        echo $children->nodeName;
    }
    

    Perfectly works.