开发者

grab logo of sites using php and cURL

I want to 开发者_运维知识库grab logo of website using curl and php.

what i actually want is to show a input field to the user and when user will enter a url in the field the script should grab logo of that url. i dont know how to do that.im confused :S

i there any solution? its not impossible because allmyfavs is using that .


The manual method is resolving the homepage, looking for <meta rel="shortcut icon" ... reference, or load the default http://example.com/favicon.ico as fallback, then convert it and display the image.

It's much simpler if you use free existing services, like the Google favicon API:
http://www.google.com/s2/favicons?domain=www.stackoverflow.com

Simply cut out the domain name, append it to the service API and you have a complete image tag:

$domain = parse_url($url, PHP_URL_HOST);
print "<img src='http://www.google.com/s2/favicons?domain=$domain'>";


You can use the source located on http://www.controlstyle.com/articles/programming/text/php-favicon/ . Note that it might not work in all sources where the .ico file is not inside the main page (it might, might not, you have to work it out for those cases in particular). Or you can use the Google one suggested up there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜