php-core / simplehtmldom
A fast, simple and reliable HTML document parser for PHP.
Installs: 18
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 54
Open Issues: 0
Language:HTML
Requires
- php: >=8.1
- ext-iconv: *
Requires (Dev)
Suggests
- ext-curl: Needed to support cURL downloads in class HtmlWeb
- ext-mbstring: Allows better decoding for multi-byte documents
- ext-openssl: Allows loading HTTPS pages when using cURL
This package is auto-updated.
Last update: 2025-04-09 02:17:45 UTC
README
simplehtmldom is a fast and reliable HTML DOM parser for PHP.
This is a fork of the Simple HTML DOM Parser project which aims to make "composer" compatibility better and clean-up some code, introduce type-safety and generally keep the project up-to-date.
Key features
- Purely PHP-based DOM parser (no XML extensions required).
- Works with well-formed and broken HTML documents.
- Loads webpages, local files and document strings.
- Supports CSS selectors.
Requirements
simplehtmldom requires PHP 8.1 or higher with ext-iconv enabled. Following extensions enable additional features of the parser:
- ext-mbstring (recommended)
Enables better detection for multi-byte documents. - ext-curl
Enables cURL support for the classHtmlWeb
. - ext-openssl (recommended when using cURL)
Enables SSL support for cURL.
Installation
composer require php-core/simplehtmldom
Usage
<?php require_once __DIR__. '/vendor/autoload.php'; use PHPCore\SimpleHtmlDom\HtmlWeb; $client = new HtmlWeb(); $html = $client->load('https://www.google.com/search?q=simplehtmldom'); // Returns the page title echo $html->find('title', 0)->plaintext . PHP_EOL;
Find more examples in the installation folder under examples
.
Documentation
The documentation for this library is hosted at https://php-core.com/simplehtmldom/
If you want to contribute code to the project, simply do a pull-request towards the project repository.
Authors
- S.C. Chen
- John Schlick
- logmanoriginal
- Rus Carroll
- Yousuke Kumakura
- Vadim Voituk
- PHPCore
License
The source code for simplehtmldom is licensed under the MIT license. For further information read the LICENSE file in the root directory (should be located next to this README file).
Technical notes
simplehtmldom is a purely PHP-based DOM parser that doesn't rely on external libraries like libxml, SimpleXML or PHP DOM. Doing so provides better control over the parsing algorithm and a much simpler API that even novice users can learn to use in a short amount of time.