Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

Get Favicon From Web Site Link Access External Files

Learn to get and render favicon.ico files dynamically from other servers in your PHP scripts. You can look for files and also process the DOM structure of external pages on the web. I recommend saving the favicon image file to your server converting it to a JPG or PNG file if it will be a frequently viewed image. Example 1 <?php $external_file = "http://www.developphp.com/favicon.ico"; $headers = get_headers($external_file); if(preg_match("|200|", $headers[0])) { echo "The file exists"; } else { echo "The file does not exist"; } ?> Example 2 <?php function getfavicon($url){ $favicon = ''; $html = file_get_contents($url); $dom = new DOMDocument(); $dom->loadHTML($html); $links = $dom->getElementsByTagName('link'); for ($i = 0; $i < $links->length; $i++){ $link = $links->item($i); if($link->getAttribute('rel') == 'icon'){ $favicon = $link->getAttribute('href'); } } return $favicon; } $website = "http://www.adamkhoury.com"; $favicon = getfavicon($website); echo $favicon; ?>
thumb

PHP Videos

Miscellaneous

Website Design Theme Application PHP Cookies CSS TutorialPDO Prepared Statements PHP TutorialPDO Tutorial Connect Database and Query ExampleActive Page Link Button Highlight TutorialGeoPlugin Tutorial Get User Location Information IP DetectionHashtag System and Regex PHP Programming TutorialPagination MySQLi Google Style Paged Results TutorialActive Clickable Link Function preg_replace Programming TutorialGet Favicon From Web Site Link Access External FilesRandom String Generator PHP Function Programming TutorialForce File Download Dialog In Browser TutorialCheck User Sign Up Name Ajax PHP Social Network TutorialFlat File Text Database System CMS Edit Content TutorialFlat File Text Database System Display ContentExperience Level Evaluation Programming TutorialStagger and Limit Dynamic Output in a While Loop Google AdsTwitter Dynamic Goodies Widget TutorialDynamic Google Maps Location TutorialPrepared Statements PHP mysqli Tutorial