PHP Classes

Simple HTML DOM: Manipulate HTML elements using DOMDocument

Recommend this page to a friend!
  Info   View files Example   View files View files (89)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-02-12 (5 days ago) RSS 2.0 feedStarStarStarStar 75%Total: 478 This week: 7All time: 5,943 This week: 17Up
Version License PHP version Categories
voku-simple_html_dom 2.0.78MIT/X Consortium ...5.3HTML, PHP 5, Parsers
Collaborate with this project Author

simple_html_dom - github.com

Description

This class can manipulate HTML elements using DOMDocument

This is a fork of SimpleHTMLDOM package that uses DOMDocument classes instead of HTML string manipulation.

It can parse and tolerate invalid HTML and supports UTF-8 documents

It can search tags on a HTML page with selectors just like jQuery.

Picture of Lars Moelleken
  Performance   Level  
Innovation award
Innovation award
Nominee: 11x

Winner: 1x

 

Details

Build Status Coverage Status Codacy Badge Latest Stable Version Total Downloads License Donate to this project using Paypal Donate to this project using Patreon

:scroll: Simple Html Dom Parser for PHP

A HTML DOM parser written in PHP - let you manipulate HTML in a very easy way! This is a fork of PHP Simple HTML DOM Parser project but instead of string manipulation we use DOMDocument and modern php classes like "Symfony CssSelector".

  • PHP 7.0+ & 8.0 Support
  • PHP-FIG Standard
  • Composer & PSR-4 support
  • PHPUnit testing via Travis CI
  • PHP-Quality testing via SensioLabsInsight
  • UTF-8 Support (more support via "voku/portable-utf8")
  • Invalid HTML Support (partly ...)
  • Find tags on an HTML page with selectors just like jQuery
  • Extract contents from HTML in a single line

Install via "composer require"

composer require voku/simple_html_dom
composer require voku/portable-utf8 # if you need e.g. UTF-8 fixed output

Quick Start

use voku\helper\HtmlDomParser;

require_once 'composer/autoload.php';

...
$dom = HtmlDomParser::str_get_html($str);
// or 
$dom = HtmlDomParser::file_get_html($file);

$element = $dom->findOne('#css-selector'); // "$element" === instance of "SimpleHtmlDomInterface"

$elements = $dom->findMulti('.css-selector'); // "$elements" === instance of SimpleHtmlDomNodeInterface<int, SimpleHtmlDomInterface>

$elementOrFalse = $dom->findOneOrFalse('#css-selector'); // "$elementOrFalse" === instance of "SimpleHtmlDomInterface" or false

$elementsOrFalse = $dom->findMultiOrFalse('.css-selector'); // "$elementsOrFalse" === instance of SimpleHtmlDomNodeInterface<int, SimpleHtmlDomInterface> or false
...

Examples

github.com/voku/simple_html_dom/tree/master/example

API

github.com/voku/simple_html_dom/tree/master/README_API.md

Support

For support and donations please visit Github | Issues | PayPal | Patreon.

For status updates and release announcements please visit Releases | Twitter | Patreon.

For professional support please contact me.

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
  • Thanks to StyleCI for the simple but powerfull code style check.
  • Thanks to PHPStan && Psalm for relly great Static analysis tools and for discover bugs in the code!

License

FOSSA Status

  Files folder image Files  
File Role Description
Files folder image.github (3 files, 1 directory)
Files folder imagebuild (2 files, 1 directory)
Files folder imageexample (16 files)
Files folder imagesrc (1 directory)
Files folder imagetests (12 files, 1 directory)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .styleci.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.php_cs Example Example script
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file README_API.md Doc. Documentation

Downloadvoku-simple_html_dom-2023-02-12.zip 286KB
Downloadvoku-simple_html_dom-2023-02-12.tar.gz 249KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Portable UTF-8 Download .zip .tar.gz Strin Required
 Version Control Reuses Unique User Downloads Download Rankings  
 100%4
Total:478
This week:7
All time:5,943
This week:17Up
User Ratings User Comments (1)
 All time
Utility:93%StarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:93%StarStarStarStarStar
Examples:93%StarStarStarStarStar
Tests:-
Videos:-
Overall:75%StarStarStarStar
Rank:130
 
nice
6 years ago (muabshir)
80%StarStarStarStarStar