PHP code example of thesoftwarefanatics / php-html-parser
1. Go to this page and download the library: Download thesoftwarefanatics/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/ */
thesoftwarefanatics / php-html-parser example snippets
// Assuming you installed from Composer:
$dom->loadFromFile('tests/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->load('http://google.com');
$html = $dom->outerHtml; // same result as the first example
// Assuming you installed from Composer:
Connector;
$dom = new Dom;
$dom->loadFromUrl('http://google.com', [], new Connector);
$html = $dom->outerHtml;
// Assuming you installed from Composer:
$dom->loadStr('<html>String</html>', []);
$html = $dom->outerHtml;
// Assuming you installed from Composer:
$dom->setOptions([
'strict' => true, // Set a global option to enable strict html parsing.
]);
$dom->load('http://google.com', [
'whitespaceTextNode' => false, // Only applies to this load.
]);
$dom->load('http://gmail.com'); // will not have whitespaceTextNode set to false.