voku / simple_html_dom

📜 Modern Simple HTML DOM Parser for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

question: Is it a bug of find() it search from its own node not from child nodes?

onemans-battle opened this issue · comments

The find () function does not start looking for elements from child nodes, but starts from its own node? Is this a bug or is it just designed like this?

$html='
<div class="class">
    <strong>1</strong>
    <div>
        <strong>2</strong>
    </div>
</div> 
';
$d=HtmlDomParser::str_get_html($html);
$div=$d->find('.class',0);
$v=$div->find('div strong',0)->text();//echo 1 not 2

but the https://github.com/sunra/php-simple-html-dom-parser will echo 2

Good question :octocat: ... jQuery also returns "1" here and I also would expect all selectors from the current node. Do you know why we should use only the child nodes?

Thank you for your reply. It may be because I used it sunra/php-simple-html-dom-parser before, so I used to think that this should be consistent with the result produced by ->find('.class div strong') (echo 2).