| 1 |
# PHP Simple HTML DOM Parser |
| 2 |
|
| 3 |
[](https://github.com/simplehtmldom/simplehtmldom/blob/master/LICENSE](https://github.com/simplehtmldom/simplehtmldom/blob/master/LICENSE](https://github.com/simplehtmldom/simplehtmldom/blob/master/LICENSE) |
| 4 |
[](https://sourceforge.com/projects/simplehtmldom/files/simplehtmldom/](https://sourceforge.com/projects/simplehtmldom/files/simplehtmldom/](https://sourceforge.com/projects/simplehtmldom/files/simplehtmldom/) |
| 5 |
[](https://github.com/simplehtmldom/simplehtmldom/actions/workflows/basic_tests.yml](https://github.com/simplehtmldom/simplehtmldom/actions/workflows/basic_tests.yml](https://github.com/simplehtmldom/simplehtmldom/actions/workflows/basic_tests.yml) |
| 6 |
[](https://packagist.org/packages/simplehtmldom/simplehtmldom](https://packagist.org/packages/simplehtmldom/simplehtmldom](https://packagist.org/packages/simplehtmldom/simplehtmldom) |
| 7 |
|
| 8 |
simplehtmldom is a fast and reliable HTML DOM parser for PHP. |
| 9 |
|
| 10 |
## Key features |
| 11 |
|
| 12 |
* Purely PHP-based DOM parser (no XML extensions required). |
| 13 |
* Works with well-formed and broken HTML documents. |
| 14 |
* Loads webpages, local files and document strings. |
| 15 |
* Supports CSS selectors. |
| 16 |
|
| 17 |
## Requirements |
| 18 |
|
| 19 |
simplehtmldom requires **PHP 5.6 or higher** with [](https://www.php.net/manual/en/book.iconv.phpext-iconv](https://www.php.net/manual/en/book.iconv.php](https://www.php.net/manual/en/book.iconv.php) enabled. Following extensions enable additional features of the parser: |
| 20 |
|
| 21 |
* [](https://secure.php.net/manual/en/book.mbstring.phpext-mbstring](https://secure.php.net/manual/en/book.mbstring.php](https://secure.php.net/manual/en/book.mbstring.php) (recommended) \ |
| 22 |
Enables better detection for multi-byte documents. |
| 23 |
* [](https://secure.php.net/manual/en/book.curl.phpext-curl](https://secure.php.net/manual/en/book.curl.php](https://secure.php.net/manual/en/book.curl.php) \ |
| 24 |
Enables cURL support for the class `HtmlWeb`. |
| 25 |
* [](https://secure.php.net/manual/en/book.openssl.phpext-openssl](https://secure.php.net/manual/en/book.openssl.php](https://secure.php.net/manual/en/book.openssl.php) (recommended when using cURL) \ |
| 26 |
Enables SSL support for cURL. |
| 27 |
|
| 28 |
## Installation |
| 29 |
|
| 30 |
**Manually**: |
| 31 |
|
| 32 |
Download the latest release from [](https://sourceforge.net/projects/simplehtmldom/files/latestSourceForge](https://sourceforge.net/projects/simplehtmldom/files/latest](https://sourceforge.net/projects/simplehtmldom/files/latest) and extract the files in the vendor folder of your project. |
| 33 |
|
| 34 |
**Composer**: |
| 35 |
|
| 36 |
```sh |
| 37 |
composer require simplehtmldom/simplehtmldom |
| 38 |
``` |
| 39 |
|
| 40 |
**Git**: |
| 41 |
|
| 42 |
``` |
| 43 |
git clone git://git.code.sf.net/p/simplehtmldom/repository simplehtmldom |
| 44 |
``` |
| 45 |
|
| 46 |
_Note_: The [](https://github.com/simplehtmldom/simplehtmldomGitHub repository](https://github.com/simplehtmldom/simplehtmldom](https://github.com/simplehtmldom/simplehtmldom) serves as a mirror for the SourceForge project. We currently accept pull requests and issues only via SourceForge. |
| 47 |
|
| 48 |
## Usage |
| 49 |
|
| 50 |
This example illustrates how to return the page title: |
| 51 |
|
| 52 |
<details><summary>Manually</summary> |
| 53 |
|
| 54 |
``` |
| 55 |
<?php |
| 56 |
include_once 'HtmlWeb.php'; |
| 57 |
use simplehtmldom\HtmlWeb; |
| 58 |
|
| 59 |
$client = new HtmlWeb(); |
| 60 |
$html = $client->load('https://www.google.com/search?q=simplehtmldom'); |
| 61 |
|
| 62 |
// Returns the page title |
| 63 |
echo $html->find('title', 0)->plaintext . PHP_EOL; |
| 64 |
``` |
| 65 |
|
| 66 |
</details> |
| 67 |
|
| 68 |
<details><summary>Using composer</summary> |
| 69 |
|
| 70 |
``` |
| 71 |
<?php |
| 72 |
include_once 'vendor/autoload.php'; |
| 73 |
use simplehtmldom\HtmlWeb; |
| 74 |
|
| 75 |
$client = new HtmlWeb(); |
| 76 |
$html = $client->load('https://www.google.com/search?q=simplehtmldom'); |
| 77 |
|
| 78 |
// Returns the page title |
| 79 |
echo $html->find('title', 0)->plaintext . PHP_EOL; |
| 80 |
``` |
| 81 |
|
| 82 |
</details> |
| 83 |
|
| 84 |
Find more examples in the installation folder under `examples`. |
| 85 |
|
| 86 |
## Documentation |
| 87 |
|
| 88 |
The documentation for this library is hosted at [](https://simplehtmldom.sourceforge.io/docs/https://simplehtmldom.sourceforge.io/docs/](https://simplehtmldom.sourceforge.io/docs/](https://simplehtmldom.sourceforge.io/docs/) |
| 89 |
|
| 90 |
## Getting involved |
| 91 |
|
| 92 |
There are various ways for you to get involved with simplehtmldom. Here are a few: |
| 93 |
|
| 94 |
* Share this project with your friends (Twitter, Facebook, ..._you name it_...). |
| 95 |
* Report [](https://sourceforge.net/p/simplehtmldom/bugs/bugs](https://sourceforge.net/p/simplehtmldom/bugs/](https://sourceforge.net/p/simplehtmldom/bugs/) (SourceForge). |
| 96 |
* Request [](https://sourceforge.net/p/simplehtmldom/feature-requests/features](https://sourceforge.net/p/simplehtmldom/feature-requests/](https://sourceforge.net/p/simplehtmldom/feature-requests/) (SourceForge). |
| 97 |
* Discuss existing bugs, features and ideas. |
| 98 |
|
| 99 |
If you want to contribute code to the project, please open a [](https://sourceforge.net/p/simplehtmldom/feature-requests/feature request](https://sourceforge.net/p/simplehtmldom/feature-requests/](https://sourceforge.net/p/simplehtmldom/feature-requests/) and include your patch with the message. |
| 100 |
|
| 101 |
## Authors |
| 102 |
|
| 103 |
* [](https://sourceforge.net/u/me578022/S.C. Chen](https://sourceforge.net/u/me578022/](https://sourceforge.net/u/me578022/) |
| 104 |
* [](https://sourceforge.net/u/john_schlick/John Schlick](https://sourceforge.net/u/john_schlick/](https://sourceforge.net/u/john_schlick/) |
| 105 |
* [](https://sourceforge.net/u/logmanoriginal/logmanoriginal](https://sourceforge.net/u/logmanoriginal/](https://sourceforge.net/u/logmanoriginal/) |
| 106 |
* Rus Carroll |
| 107 |
* Yousuke Kumakura |
| 108 |
* Vadim Voituk |
| 109 |
|
| 110 |
## License |
| 111 |
|
| 112 |
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). |
| 113 |
|
| 114 |
## Technical notes |
| 115 |
|
| 116 |
simplehtmldom is a purely PHP-based DOM parser that doesn't rely on external libraries like [](https://www.php.net/manual/en/book.libxml.phplibxml](https://www.php.net/manual/en/book.libxml.php](https://www.php.net/manual/en/book.libxml.php), [](https://www.php.net/manual/en/book.simplexml.phpSimpleXML](https://www.php.net/manual/en/book.simplexml.php](https://www.php.net/manual/en/book.simplexml.php) or [](https://www.php.net/manual/en/book.dom.phpPHP DOM](https://www.php.net/manual/en/book.dom.php](https://www.php.net/manual/en/book.dom.php). 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. |
| 117 |
|