see the article/answer
How do you parse and process HTML/XML in PHP?
How can one parse HTML/XML and extract information from it?
https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php
How to modify HTML elements:
// Create DOM from string
- $html = str_get_html('<div id="hello">Hello</div><div id="world">World</div>');
- $html->find('div', 1)->class = 'bar';
- $html->find('div[id=hello]', 0)->innertext = 'foo';
- echo $html;
Extract content from HTML:
// Dump contents (without tags) from HTML
echo file_get_html('http://www.google.com/')->plaintext;
How to get HTML elements:
- // Create DOM from URL or file
- foreach($html->find('img') as $element)
- echo $element->src . '<br>';
- foreach($html->find('a') as $element)
- echo $element->href . '<br>';