I can't edit my previous post .. ? below is newer function, removed some mistakes
function getFavicon($url) {
$check = parse_url($url);
if(empty($check['scheme'])) { // check if there http whatever, if not add it.
$url = 'http://' . ltrim($url, '/');
}
$check = parse_url($url);
if (!empty($check['host'])) { // Get host path (thats all we need , get rid of path) check if smth is there
$url = $check['host'];
$url = $check['scheme'] . '://' . $url; // put back original scheme
}
else {
return false;
}
$href = false;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,2);
curl_setopt($ch, CURLOPT_TIMEOUT, 2); //timeout in seconds
$content = curl_exec($ch);
if (!empty($content)) {
$dom = new DOMDocument();
@$dom->loadHTML($content); //supress errors
$items = $dom->getElementsByTagName('link');
foreach ($items as $item) {
$rel = $item->getAttribute('rel');
if ($rel == 'icon' or $rel == 'shortcut icon') {
$href = $item->getAttribute('href');
break;
}
}
}
if ($href != false) {
$href = parse_url($href);
return $url . $href['path'];
}
return false;
}