One idea I can give you is, first capture the url of the site using curl()
or file_get_contents()
:
<?php
if (isset($_GET['img'])) {
$favicon = $_GET['img'];
print_r(array('favicon'=>$favicon));
die();
}
function capturarFaviconSite($url_metodo) {
$script = "\n" . '<script>' .
'function captureFavicon() {
var objSerializer = new XMLSerializer(), favicon;
var expFormat = /href="(.+).[png|ico|jpg|(.+)?v=(.+)]"/gi;
var expCheck = /(rel="icon"|rel="shortcut icon"|type="image\/png"|rel="apple-touch-icon")/gi;
var all = document.querySelectorAll("link");
for (var i in all) {
var fav = objSerializer.serializeToString(all[i]);
if (expCheck.test(fav)) {
favicon = expFormat.exec(fav)[0]
.replace("href=\"","")
.replace("\"","");
break;
}
}
if (favicon!="") {
location.href="?img="+escape(favicon);
}
}';
$html = file_get_contents($url_metodo);
return preg_replace('/<\/head>/',$script . 'captureFavicon();'."\n".'</script></head>',$html);
}
echo capturarFaviconSite('http://www.uol.com.br');
In the case above, what I'm doing is returning this by a javascript method:
function captureFavicon() {
var objSerializer = new XMLSerializer(), favicon;
var expFormat = /href="(.+).[png|ico|jpg|(.+)?v=(.+)]"/gi;
var expCheck = /(rel="icon"|rel="shortcut icon"|type="image\/png"|rel="apple-touch-icon")/gi;
var all = document.querySelectorAll('link');
for (var i in all) {
var fav = objSerializer.serializeToString(all[i]);
if (expCheck.test(fav)) {
favicon = expFormat.exec(fav)[0]
.replace("href=\"",'')
.replace("\"",'');
break;
}
}
return favicon;
}