PHP Simple HTML DOM Parser

This is a neat and nice PHP library to use when crawling or analyzing HTML content based on a URL or a string.

  • A HTML DOM parser written in PHP5+ let you manipulate HTML in a very easy way!
  • Require PHP 5+.
  • Supports invalid HTML.
  • Find tags on an HTML page with selectors just like jQuery.
  • Extract contents from HTML in a single line.



// Create DOM from URL or file
$html = file_get_html('<a href="'">'</a>);

// Find all images
$html->find('img') as $element)
$element->src . '<br>';

// Find all links
$html->find('a') as $element)
$element->href . '<br>';


// Create DOM from string
$html = str_get_html('<div id="hello">Hello</div><div id="world">World</div>');

//Set the class to 'bar' on the second div (0, 1, 2...)
$html->find('div', 1)->class = 'bar';

//Change the inner HTML text to 'foo' in the first div with id 'hello'
$html->find('div[id=hello]', 0)->innertext = 'foo';
Tool type: