For any given site \"example.domain.tld\" or merely \"domain.tld\" I need to do the following in PHP:
As Iain Fraser said, the Favicon class from controlstyle.com doesn't works with all test case.
Basically, if provided, the shortcut icon tag can contain different URL types :
http://www.domain.com/images/fav.ico
//www.domain.com/images/fav.ico
/images/fav.ico
../images/fav.ico
Furthermore, the web page can contain a
attribute that changes how to deal with relative URL and absoute path...
So I've written a PHP class that works with all these cases.
First, it tries to get the favicon URL from the attribute, and fallback to the default favicon URI (//www.domain.com/favicon.ico) in case of failure.
You can grab it on my website here : http://www.finalclap.com/faq/477-php-favicon-find-download or install it using composer : composer require vincepare/favicon-downloader
.
How to use :
icoExists){
echo "Favicon found : ".$favicon->icoUrl."\n";
// Saving favicon to file
$filename = 'favicon-'.time().'.'.$favicon->icoType;
file_put_contents($filename, $favicon->icoData);
echo "Saved to ".$filename."\n\n";
} else {
echo "No favicon for ".$favicon->url."\n\n";
}
?>