1. Go to this page and download the library: Download natlibfi/php-html-parser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Assuming you installed from Composer:
$dom->loadFromFile('tests/data/big.html');
$contents = $dom->find('.content-border');
echo count($contents); // 10
foreach ($contents as $content)
{
// get the class attr
$class = $content->getAttribute('class');
// do something with the html
$html = $content->innerHtml;
// or refine the find some more
$child = $content->firstChild();
$sibling = $child->nextSibling();
}
// Assuming you installed from Composer:
$dom->loadFromUrl('http://google.com');
$html = $dom->outerHtml;
// or
$dom->loadFromUrl('http://google.com');
$html = $dom->outerHtml; // same result as the first example
// Assuming you installed from Composer:
MyClient;
$dom = new Dom;
$dom->loadFromUrl('http://google.com', null, new MyClient());
$html = $dom->outerHtml;
// Assuming you installed from Composer:
$dom->loadStr('<html>String</html>');
$html = $dom->outerHtml;
// Assuming you installed from Composer:
\Options;
$dom = new Dom;
$dom->setOptions(
// this is set as the global option level.
(new Options())
->setStrict(true)
);
$dom->loadFromUrl('http://google.com',
(new Options())->setWhitespaceTextNode(false) // only applies to this load.
);
$dom->loadFromUrl('http://gmail.com'); // will not have whitespaceTextNode set to false.