开发者

DOMXpath | Select the innermost divs

Im looking for a way to select the innermost div with PHP

for example:

<div>
    <div>
        <div>
            -
        </div>
    </div>
    <div>
        <div>
            <div>
                -
            </div>
        </div>
    </div>
</div>

The DIV's containing the - would be selected in the NodeList

Im using DOMDocument and DOMXpath to go threw the html, heres and example of what one of my methods so you can see the way my class is created.

public function getkeywords()
{
    foreach($this->Xpath->query('/html/head/meta[@content][@name="keywords"][1]') as $node)
    {
        $words = $node->getAttribute('content');
        if($words)
        {
            return explode(',',str_replace(array(", "," ,"),",",$words));
        }
        开发者_StackOverflow社区return false;
    }
    return false;       
}


Im looking for a way to select the innermost div

That should be:

//div[not(descendant::div)]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜