Exemplo n.º 1
0
\t\t<div id="div4" class="hello2">
\t\t\ttext5
\t\t</div>
\t</div>
\ttext6
\t<div id="div5" class="hello2">
\t</div>
\ttext7
</body> 
</html> 
HTML;
$doc = new HTMLDocument($html);
echo 'by id:';
var_dump($doc->getElementById('div3')->getOuterHTML());
echo 'by tag:';
foreach ($doc->getElementsByTag('div') as $elem) {
    var_dump($elem->__toString());
}
echo 'by class:';
foreach ($doc->getElementsByClass('hello') as $elem) {
    var_dump($elem->__toString());
}
echo 'by attribute:';
foreach ($doc->getElementsByAttribute('class', 'hello2') as $elem) {
    var_dump($elem->__toString());
}
echo 'find----' . PHP_EOL;
echo 'by tag';
foreach ($doc->find('div') as $elem) {
    var_dump($elem->__toString());
}