PHP – Get Elements Attribute form HTML

This php function helps you to get the required attributes from the elements to a given HTML.

Code Example:

function getHtmlElementsAttribute($html){
	$doc = new DOMDocument();
	$tags = $doc->getElementsByTagName('link');
	foreach ($tags as $tag){
		echo $tag->getAttribute('href');
	$tags = $doc->getElementsByTagName('img');
	foreach ($tags as $tag){
		echo $tag->getAttribute('src');

$html = "<html><link href=''></link><img src='' /><img src='' /></html>";


Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail