I ran into something very, very interesting today. Google Favicon API
(A Favorite Icon API)
. It’s an API that allows you to pull websites Favicons, plus the API dynamically converts the image into a PNG format. This actually comes at a great time because I was just thinking the other day that since I have the option to add offsite URL’s to my site now. Would’nt it would be supa cool if I could also included their Favicon? To beak it down if you look into my site’s right side navigation you will see the “Links” category. Well I thought it would be nice, I mean supa cool if I had a script that could automatically include the corresponding sites Favicons.  And BAM! Thanks Google Favicon API. I wrapped this APIs up with some cURL and a little PHP and now I have a working PHP function. I don’t know much about the Google Favicon API but it looks like it’s been around for about a year. So it’s a good chance that this API could suddenly up and move or disappear all togehter. Basically what I’m saying is I don’t know how long the good times will last. So in my opinion I suggest you consider the use of this script temporary until you can get the time to build a much reliable one yourself.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?PHP
function getFavicon($var){
$filName=substr($var,0,-4);
$fp = fopen ('folder/'.$filName.'.png', 'w+');
$ch = curl_init('http://www.google.com/s2/favicons?domain='.$var);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);

}

$var='techcrunch.com';
getFavicon($var);
?>