PHP - 获取网站的favicon并在必要时将其转换为png [英] PHP - getting a site's favicon and converting it to png if necessary

查看:358
本文介绍了PHP - 获取网站的favicon并在必要时将其转换为png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于任何给定的网站example.domain.tld或仅仅是domain.tld我需要在PHP中执行以下操作:

For any given site "example.domain.tld" or merely "domain.tld" I need to do the following in PHP:


  • 如果该网站有图标,请在任何地方获取它


    • 如果它还不是PNG,请将其转换为PNG

    • 将其保存到/favicons/example.domain.tld.png

    任何想法?我被不可靠的文件格式和favicon的位置所困扰,但如果可能的话我想避免使用file_get_contents下载整个页面源,以便在标题中找到它。转换为png似乎也很重要。

    Any ideas? I'm being stumped by the unreliable fileformat and location of the favicons, but if at all possible I want to avoid downloading the entire source of the page with file_get_contents in order to find it in the headers. Also converting to png seems nontrivial.

    谢谢,

    Mala

    推荐答案

    通常情况下,我在提出问题后不久就找到了一个可通过的解决方案 - 让google为你做的工作:

    As is typical, I found a passable solution shortly after asking the question - let google do the work for you:

    http://www.google.com/s2/favicons?domain=URL

    返回16x16 png

    returns a 16x16 png

    这篇关于PHP - 获取网站的favicon并在必要时将其转换为png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆