How to get a website's favicon with PHP?

后端 未结 13 1112
醉梦人生
醉梦人生 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:31

    If you want to retrieve the favicon from a particular website, you simply need to fetch favicon.ico from the root of their website. Like so:

    $domain = "www.example.com";
    $url = "http://".$domain."/favicon.ico";
    $icondata = file_get_contents($url);
    
    ... you can now do what you like with the icon data
    

提交回复
热议问题