paquettg/php-html-parser
Fast, lightweight HTML parser for PHP that turns messy markup into a DOM-like tree. Crawl and scrape pages, query elements with CSS selectors, and extract text/attributes easily. Works with imperfect HTML and focuses on simple, fluent usage.
composer require paquettg/php-html-parser). No Laravel-specific helpers (e.g., Blade directives).Mailable).composer require paquettg/php-html-parser
HtmlParser.use Paquettg\HtmlParser\HtmlParser;
$html = '<div class="user"><span>John</span></div>';
$parser = new HtmlParser($html);
$name = $parser->find('.user span')->text(); // "John"
// app/Providers/AppServiceProvider.php
$this->app->bind('html', function () {
return new HtmlParser();
});
// app/Providers/BladeServiceProvider.php
Blade::directive('parse', function ($expression) {
return "<?php echo app('html')->parse({$expression}); ?>";
});
dom extension (enabled by default).file_get_contents()).DOMDocument).composer.json and create a helper class/facade.README for team-specific selectors (e.g., .product-price).paquettg/php-html-parser for common solutions.:contains vs. CSS).Redis).DOMDocument or a headless browser.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Malformed HTML crashes parser | Selectors fail silently or throw errors | Validate HTML with libxml_use_internal_errors() |
| Selector syntax errors | Incorrect data extraction | Use IDE autocomplete or test fixtures |
PHP dom extension missing |
Runtime errors | Document requirements in README |
| High memory usage | Worker timeouts (queues) | Optimize selectors or use chunking |
| PHP version incompatibility | Breaking changes | Pin version in composer.json |
How can I help you explore Laravel packages today?