PHP code example of gaswelder / htmlparser
1. Go to this page and download the library: Download gaswelder/htmlparser 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/ */
gaswelder / htmlparser example snippets
use \gaswelder\htmlparser\Parser;
use \gaswelder\htmlparser\ParsingException;
try {
$doc = Parser::parse($html);
} catch(ParsingException $e) {
// ...
return;
}
$images = $doc->querySelectorAll('#posts .post img');
foreach ($images as $img) {
$src = $img->getAttribute('src');
echo $src, "\n";
}
$list = $doc->getElementsByTagName('a');
echo $list, PHP_EOL;