/**
* Get favicon link from a URL
* @return mixed Returns string if found, else boolean false
* @param string The url to search
**/
function getFavicon($url)
{
$href = false;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
if (!empty($content))
{
$dom = new DOMDocument();
@$dom->loadHTML($content);
$items = $dom->getElementsByTagName('link');
foreach ($items as $item)
{
$rel = $item->getAttribute('rel');
if ($rel == 'icon' or $rel == 'shortcut icon')
{
$href = $item->getAttribute('href');
break;
}
}
}
return $href;
}
You would then have to parse the return value to determine whether it is a full URI or a relative path.