How to get a website's favicon with PHP?

后端 未结 13 1137
醉梦人生
醉梦人生 2020-12-02 16:08

I want to get, requested website\'s favicon with PHP. I have been recommended using Google\'s favicon service but it is not functional. I want to do something on my own but

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 16:40

    Found this thread... I have written a WordPress plugin that encompasses a lot of variations on retrieving the favicon. Since there are a lot the GPL code: http://plugins.svn.wordpress.org/wp-favicons/trunk/

    It lets you run a server which you can request icons from via xml rpc requests so any client can request icons. It does have a plugin structure so you can try google, getfavicon, etc... to see if one of these services delivers anything. If not then it goes into a icon fetching mode taking into account all http statusses (301/302/404) and does it best to find an icon anywhere. After this it uses image library functions to check inside the file if it is really an image and what kind of image (sometimes the extension is wrong) and it is pluggable so you can add after image conversions or extra functionality in the pipeline.

    the http fetching file does some logic around what i see above: http://plugins.svn.wordpress.org/wp-favicons/trunk/includes/server/class-http.php

    but it is only part of the pipeline.

    can get pretty complex once you dive into it.

提交回复
热议问题