Return to Snippet

Revision: 62282
at February 13, 2013 04:23 by phpdev


Updated Code
/**
 * Get favicon from a URL.
 * 
 * @author Pierre-Henry Soria <[email protected]>
 * @copyright (c) 2013, Pierre-Henry Soria. All Rights Reserved.
 * @param string $sUrl
 * @return string The favicon image.
 */
function get_favicon($sUrl)
{
	$sApiUrl = 'http://www.google.com/s2/favicons?domain=';
	$sDomainName = get_domain($sUrl);
	
	return $sApiUrl . $sDomainName;
}

/**
 * Get domain name from a URL (helper function).
 * 
 * @author Pierre-Henry Soria <[email protected]>
 * @copyright (c) 2013, Pierre-Henry Soria. All Rights Reserved.
 * @param string $sUrl
 * @return string $sUrl Returns the URL to lower case and without the www. if present in the URL.
 */
function get_domain($sUrl)
{
        $sUrl = str_ireplace('www.', '', $sUrl);
        $sHost = parse_url($sUrl, PHP_URL_HOST);
        return $sHost;
}

Revision: 62281
at February 13, 2013 04:07 by phpdev


Initial Code
/**
 * Get favicon from a URL.
 * 
 * @author Pierre-Henry Soria <[email protected]>
 * @copyright (c) 2013, Pierre-Henry Soria. All Rights Reserved.
 * @param string $sUrl
 * @return string The favicon image.
 */
function get_favicon($sUrl)
{
	$sApiUrl = 'http://s2.googleusercontent.com/s2/favicons?domain=';
	$sDomainName = get_domain($sUrl);
	
	return $sApiUrl . $sDomainName;
}

/**
 * Get domain name from a URL (helper function).
 * 
 * @author Pierre-Henry Soria <[email protected]>
 * @copyright (c) 2013, Pierre-Henry Soria. All Rights Reserved.
 * @param string $sUrl
 * @return string $sUrl Returns the URL to lower case and without the www. if present in the URL.
 */
function get_domain($sUrl)
{
        $sUrl = str_ireplace('www.', '', $sUrl);
        $sHost = parse_url($sUrl, PHP_URL_HOST);
        return $sHost;
}

Initial URL

                                

Initial Description
**Example of use:**

&lt;a href="http://www.php.net/manual/en/index.php"&gt;&lt;img src="&lt;?php echo get_favicon('http://www.php.net/manual/en/index.php') ?&gt;" alt="Favicon" title="See PHP documentation" width="16" height="16" /&gt;&lt;/a&gt;

Initial Title
Get the Favicon from a website

Initial Tags
url, php, image, script

Initial Language
PHP