发现使用phpQuery()的元素是什么

时间:2012-02-17 02:18:21

标签: php html-parsing phpquery

我使用phpQuery来解析HTML文件的每个元素,我做的是这样的:

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

但是,我需要知道正在解析哪个元素(table,div,p ...)。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

好的,我点了。由于phpQuery基于DOMDocument,我只需要使用属性nodeName,如下所示:

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

完美无缺。