发现使用phpQuery()的元素

发现使用phpQuery()的元素,php,html-parsing,phpquery,Php,Html Parsing,Phpquery,我使用phpQuery解析HTML文件的每个元素,我所做的是这样的: foreach (pq('body')->children() as $children) { // do some code here } foreach (pq('body')->children() as $children) { echo $children->nodeName; } 但是,我需要知道正在解析哪个元素(table,div,p…) 我该怎么做呢?好的,我编辑它。由于p

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

foreach (pq('body')->children() as $children) {
    // do some code here
}
foreach (pq('body')->children() as $children) {
    echo $children->nodeName;
}
但是,我需要知道正在解析哪个元素(table,div,p…)


我该怎么做呢?

好的,我编辑它。由于phpQuery是基于DOMDocument的,所以我必须使用属性nodeName,如下所示:

foreach (pq('body')->children() as $children) {
    // do some code here
}
foreach (pq('body')->children() as $children) {
    echo $children->nodeName;
}
非常有效