emanueleminotto/simple-html-dom
Simple HTML DOM parser for PHP. Provides a lightweight API to load HTML from strings/files/URLs, traverse and query elements, and extract text/attributes. Handy for scraping, data extraction, and quick HTML manipulation without a full browser.
find(), innertext, etc.), reducing learning curve for frontend developers or teams transitioning from JS.Http::get()) or Blade templates for dynamic content parsing.spatie/array-to-html or laravelcollective/html.create_function, preg_replace callbacks) and lack of modern PHP constructs.DOMDocument as a fallback).Http facade for URL scraping, but lacks built-in retry logic or middleware support.@scrape), but requires manual implementation.| Risk Area | Severity | Description |
|---|---|---|
| Security | High | Unpatched vulnerabilities in underlying Simple HTML DOM or PHP versions. |
| PHP 8.x Compatibility | High | Deprecated syntax and lack of modern PHP features. |
| Maintenance | Medium | Abandoned project; no updates for 8+ years. |
| Performance | Low | Lightweight, but no benchmarks vs. modern alternatives (e.g., Symfony Panther). |
| Testing | Medium | Difficult to unit test; relies on real HTML parsing. |
| Scalability | Low | Not designed for high-throughput scraping (e.g., no connection pooling). |
symfony/dom-crawler or spatie/array-to-html suffice?rector/rector to auto-fix deprecated syntax if forking.composer require emanueleminotto/simple-html-dom:^1.9
use SimpleHtmlDom\SimpleHtmlDom;
// Parse from URL (Laravel HTTP client recommended)
$html = file_get_html('https://example.com');
$links = $html->find('a', 0)->href; // CSS-like selector
// Parse from string
$dom = str_get_html('<div>Test</div>');
echo $dom->innertext; // "Test"
// app/Providers/ScraperServiceProvider.php
public function register()
{
$this->app->singleton(SimpleHtmlDom::class, function () {
return new SimpleHtmlDom();
});
}
try-catch for file_get_html() (network/parse errors).htmlspecialchars() on output).| Component | Compatibility | Notes |
|---|---|---|
| PHP 7.2–7.4 | ✅ Full support | Use exact version (^1.9). |
| PHP 8.x | ❌ Partial (requires polyfills) | Deprecated functions may break. |
| Laravel 5.8–8.x | ✅ Works with minor tweaks | No native Laravel integrations. |
| Laravel 9.x+ | ⚠️ High risk | PHP 8.1+ incompatibilities. |
| Symfony Components | ❌ No DI/Config integration | Manual setup required. |
| Modern PHP Tools | ❌ No PSR-15/PSR-18 support | No async HTTP clients. |
app/Services/HtmlScraper.php).class HtmlScraper {
public function scrapeLinks(string $url): array
{
$html = file_get_html($url);
return array_map(fn($a) => $a->href, $html->find('a'));
}
}
symfony/dom-crawler.Simple HTML DOM may have unpatched vulnerabilities.How can I help you explore Laravel packages today?