How can I retrieve the favicon of a website?

前端 未结 6 2020
滥情空心
滥情空心 2021-01-30 09:40

I want to list featured websites on my website and I thought it would be cool to honor and use their favicon. How do I get it from the domain for an arbitrary URL in either JSP

6条回答
  •  爱一瞬间的悲伤
    2021-01-30 10:02

    To get the favicon of a website, you need to load the index HTML of each featured website and check for either of the following:

    HTML:

    
    
    
    

    XHTML:

    
    
    
    

    Internet Explorer may use a slightly different format:

    
    

    Also note that since most web browsers do not require the HTML link to retrieve a favicon, you should also check for favicon.ico in the website's document root, if none of the above link references are found.

    With PHP, it is easy to get the HTML contents of a web page by using file_get_contents($url):

    $url = 'http://www.exmaple.com';
    $output = file_get_contents($url);
    

提交回复
热议问题