PHP HTML and DOM Parsing

DOMDocument

// Create a new DOMDocument object.
$dom = new DOMDocument; 

// Load the HTML page into the object.
$dom->loadHTML($html);

// Once the HTML is loaded into the object, access nodes and child elements:

// Get an element by it's ID.
$my_div_obj = $dom->getElementById('mydiv');

// Get all elements of a type.
$anchors = $dom->getElementsByTagName('a'); 
foreach ($anchors as $anchor) {
    echo $dom->saveHTML($anchor); // Prints the text-only content of the anchor.
}

Get all image tags

preg_match_all('/<img[^>]+>/i',$html, $result);