I want to list featured websites on my website and I thought it would be cool to honor and use their favicon. How do I get it from the domain for an arbitrary URL in either JSP or XSLT? I can fire off PHP or javascript, but XSLT is the preferred methodology.
+12
A:
To get the favicon of a website, you need to load the index HTML of each featured website and check for either of the following:
HTML:
<link rel="icon" type="image/vnd.microsoft.icon" href="http://example.com/image.ico">
<link rel="icon" type="image/png" href="http://example.com/image.png">
<link rel="icon" type="image/gif" href="http://example.com/image.gif">
XHTML:
<link rel="icon" type="image/vnd.microsoft.icon" href="/somepath/image.ico" />
<link rel="icon" type="image/png" href="/somepath/image.png" />
<link rel="icon" type="image/gif" href="/somepath/image.gif" />
Internet Explorer may use a slightly different format:
<link rel="SHORTCUT ICON" href="http://www.example.com/myicon.ico" />
Also note that since most web browsers do not require the HTML link to retrieve a favicon, you should also check for favicon.ico
in the website's document root, if none of the above link references are found.
With PHP, it is easy to get the HTML contents of a web page by using file_get_contents($url)
:
$url = 'http://www.exmaple.com';
$output = file_get_contents($url);
Daniel Vassallo
2010-01-02 03:14:11
EXCELLENT! Thanks for the detail Daniel. I will check out the PHP tutorial and let you know how it works out.
mobibob
2010-01-02 05:02:45