voku / simple_html_dom

📜 Modern Simple HTML DOM Parser for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

about find(). search someone out from html tag,it return blank

maoSting opened this issue · comments

it can't find tag out from html.

$html    = '<!DOCTYPE HTML>
<html>
<head>
    <title>title</title>
</head>

<body>
<div id="a">
    an apple
</div>
</body>

</html>
<div id="b">
    body
</div>';
$domTree = \voku\helper\HtmlDomParser::str_get_html($html);
var_dump($domTree->findOne('#a')->text()); // an apple

var_dump($domTree->findOne('#b')->text()); // empty

Your HTML is not valid. Please check it: https://validator.w3.org/nu/#textarea

PS: why do you need to add the DIV outside your HTML-tag?

Hello, I have a similar question (don't want to open new issue)
how to determine if we find something?
i.e

$html = HtmlDomParser::file_get_html('https://example.com');
foreach ($html->find('img#test') as $img) {
    if ($img->src) {
		echo 'found';
    }else{
		echo 'NOT found';
	}
}

Any idea?

Very helpful, although a simply isset can do the trick :)
BTW very nice work!!!
Thanks!

when i spider some web sites. some gays wrote html is an suprise...

Fixed in version v4.7.20