| 1 |
[](https://travis-ci.org/voku/simple_html_dom](https://travis-ci.org/voku/simple_html_dom](https://travis-ci.org/voku/simple_html_dom) |
| 2 |
[](https://coveralls.io/github/voku/simple_html_dom?branch=master](https://coveralls.io/github/voku/simple_html_dom?branch=master](https://coveralls.io/github/voku/simple_html_dom?branch=master) |
| 3 |
[](https://www.codacy.com/app/voku/simple_html_dom?utm_source=github.com&utm_medium=referral&utm_content=voku/simple_html_dom&utm_campaign=Badge_Grade](https://www.codacy.com/app/voku/simple_html_dom?utm_source=github.com&utm_medium=referral&utm_content=voku/simple_html_dom&utm_campaign=Badge_Grade](https://www.codacy.com/app/voku/simple_html_dom?utm_source=github.com&utm_medium=referral&utm_content=voku/simple_html_dom&utm_campaign=Badge_Grade) |
| 4 |
[](https://packagist.org/packages/voku/simple_html_dom](https://packagist.org/packages/voku/simple_html_dom](https://packagist.org/packages/voku/simple_html_dom) |
| 5 |
[](https://packagist.org/packages/voku/simple_html_dom](https://packagist.org/packages/voku/simple_html_dom](https://packagist.org/packages/voku/simple_html_dom) |
| 6 |
[](https://packagist.org/packages/voku/simple_html_dom](https://packagist.org/packages/voku/simple_html_dom](https://packagist.org/packages/voku/simple_html_dom) |
| 7 |
[](https://www.paypal.me/moelleken](https://www.paypal.me/moelleken](https://www.paypal.me/moelleken) |
| 8 |
[](https://www.patreon.com/voku](https://www.patreon.com/voku](https://www.patreon.com/voku) |
| 9 |
|
| 10 |
# :scroll: Simple Html Dom Parser for PHP |
| 11 |
|
| 12 |
A HTML DOM parser written in PHP - let you manipulate HTML in a very easy way! |
| 13 |
This is a fork of [](http://simplehtmldom.sourceforge.net/PHP Simple HTML DOM Parser project](http://simplehtmldom.sourceforge.net/](http://simplehtmldom.sourceforge.net/) but instead of string manipulation we use DOMDocument and modern php classes like "Symfony CssSelector". |
| 14 |
|
| 15 |
- PHP 7.0+ Support |
| 16 |
- PHP-FIG Standard |
| 17 |
- Composer & PSR-4 support |
| 18 |
- PHPUnit testing via Travis CI |
| 19 |
- PHP-Quality testing via SensioLabsInsight |
| 20 |
- UTF-8 Support (more support via "voku/portable-utf8") |
| 21 |
- Invalid HTML Support (partly ...) |
| 22 |
- Find tags on an HTML page with selectors just like jQuery |
| 23 |
- Extract contents from HTML in a single line |
| 24 |
|
| 25 |
|
| 26 |
### Install via "composer require" |
| 27 |
|
| 28 |
```shell |
| 29 |
composer require voku/simple_html_dom |
| 30 |
composer require voku/portable-utf8 # if you need e.g. UTF-8 fixed output |
| 31 |
``` |
| 32 |
|
| 33 |
### Quick Start |
| 34 |
|
| 35 |
```php |
| 36 |
use voku\helper\HtmlDomParser; |
| 37 |
|
| 38 |
require_once 'composer/autoload.php'; |
| 39 |
|
| 40 |
... |
| 41 |
$dom = HtmlDomParser::str_get_html($str); |
| 42 |
// or |
| 43 |
$dom = HtmlDomParser::file_get_html($file); |
| 44 |
|
| 45 |
$element = $dom->findOne('#css-selector'); // "$element" === instance of "SimpleHtmlDomInterface" |
| 46 |
|
| 47 |
$elements = $dom->findMulti('.css-selector'); // "$elements" === instance of SimpleHtmlDomNodeInterface<int, SimpleHtmlDomInterface> |
| 48 |
|
| 49 |
$elementOrFalse = $dom->findOneOrFalse('#css-selector'); // "$elementOrFalse" === instance of "SimpleHtmlDomInterface" or false |
| 50 |
|
| 51 |
$elementsOrFalse = $dom->findMultiOrFalse('.css-selector'); // "$elementsOrFalse" === instance of SimpleHtmlDomNodeInterface<int, SimpleHtmlDomInterface> or false |
| 52 |
... |
| 53 |
|
| 54 |
``` |
| 55 |
|
| 56 |
### Examples |
| 57 |
|
| 58 |
[](https://github.com/voku/simple_html_dom/tree/master/examplegithub.com/voku/simple_html_dom/tree/master/example](https://github.com/voku/simple_html_dom/tree/master/example](https://github.com/voku/simple_html_dom/tree/master/example) |
| 59 |
|
| 60 |
### Support |
| 61 |
|
| 62 |
For support and donations please visit [](https://github.com/voku/simple_html_dom/Github](https://github.com/voku/simple_html_dom/](https://github.com/voku/simple_html_dom/) | [](https://github.com/voku/simple_html_dom/issuesIssues](https://github.com/voku/simple_html_dom/issues](https://github.com/voku/simple_html_dom/issues) | [](https://paypal.me/moellekenPayPal](https://paypal.me/moelleken](https://paypal.me/moelleken) | [](https://www.patreon.com/vokuPatreon](https://www.patreon.com/voku](https://www.patreon.com/voku). |
| 63 |
|
| 64 |
For status updates and release announcements please visit [](https://github.com/voku/simple_html_dom/releasesReleases](https://github.com/voku/simple_html_dom/releases](https://github.com/voku/simple_html_dom/releases) | [](https://twitter.com/suckup_deTwitter](https://twitter.com/suckup_de](https://twitter.com/suckup_de) | [](https://www.patreon.com/voku/postsPatreon](https://www.patreon.com/voku/posts](https://www.patreon.com/voku/posts). |
| 65 |
|
| 66 |
For professional support please contact [](https://about.me/vokume](https://about.me/voku](https://about.me/voku). |
| 67 |
|
| 68 |
### Thanks |
| 69 |
|
| 70 |
- Thanks to [](https://github.comGitHub](https://github.com](https://github.com) (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc. |
| 71 |
- Thanks to [](https://www.jetbrains.comIntelliJ](https://www.jetbrains.com](https://www.jetbrains.com) as they make the best IDEs for PHP and they gave me an open source license for PhpStorm! |
| 72 |
- Thanks to [](https://travis-ci.com/Travis CI](https://travis-ci.com/](https://travis-ci.com/) for being the most awesome, easiest continous integration tool out there! |
| 73 |
- Thanks to [](https://styleci.io/StyleCI](https://styleci.io/](https://styleci.io/) for the simple but powerfull code style check. |
| 74 |
- Thanks to [](https://github.com/phpstan/phpstanPHPStan](https://github.com/phpstan/phpstan](https://github.com/phpstan/phpstan) && [](https://github.com/vimeo/psalmPsalm](https://github.com/vimeo/psalm](https://github.com/vimeo/psalm) for relly great Static analysis tools and for discover bugs in the code! |
| 75 |
|
| 76 |
### License |
| 77 |
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fvoku%2Fsimple_html_dom?ref=badge_large](https://app.fossa.io/projects/git%2Bgithub.com%2Fvoku%2Fsimple_html_dom?ref=badge_large](https://app.fossa.io/projects/git%2Bgithub.com%2Fvoku%2Fsimple_html_dom?ref=badge_large) |
| 78 |
|