回答
+1,哇,好戏! – 2011-04-26 13:08:18
从来没有见过,以前,很好:) – Simon 2011-04-26 13:19:41
为什么自己的工作,当谷歌已经完成它;) – 2011-08-11 07:55:22
您可以要求http://domain.com/favicon.ico
PHP和看看你得到一个404
如果你得到一个404那里,你可以通过网站的DOM ,寻找head
元素中link
元素与rel="icon"
中引用的不同位置。
// Helper function to see if a url returns `200 OK`.
function $resourceExists($url) {
$headers = get_headers($request);
if (! $headers) {
return FALSE;
}
return (strpos($headers[0], '200') !== FALSE);
}
function domainHasFavicon($domain) {
// In case they pass 'http://example.com/'.
$request = rtrim($domain, '/') . '/favicon.ico';
// Check if the favicon.ico is where it usually is.
if (resourceExists($request)) {
return TRUE;
} else {
// If not, we'll parse the DOM and find it
$dom = new DOMDocument;
$dom->loadHTML($domain);
// Get all `link` elements that are children of `head`
$linkElements = $dom
->getElementsByTagName('head')
->item(0)
->getElementsByTagName('link');
foreach($linkElements as $element) {
if (! $element->hasAttribute('rel')) {
continue;
}
// Split the rel up on whitespace separated because it can have `shortcut icon`.
$rel = preg_split('/\s+/', $element->getAttribute('rel'));
if (in_array('link', $rel)) {
$href = $element->getAttribute('href');
// This may be a relative URL.
// Let's assume http, port 80 and Apache
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if (substr($href, 0, strlen($url)) !== $url) {
$href = $url . $href;
}
return resourceExists($href);
}
}
return FALSE;
}
如果你想要的网址回到favicon.ico
,这是微不足道的修改上面的功能。
$address = 'http://www.youtube.com/'
$domain = parse_url($address, PHP_URL_HOST);
或从数据库中不同的结果有问题
$domain = parse_url($row['address_column'], PHP_URL_HOST);
display with
<image src="http://www.google.com/s2/favicons?domain='.$domain.'" />
- 1. wix - 网站的快捷方式图标
- 2. Favicon /快捷方式图标 - 文档中的位置?
- 3. 如何从系统快捷方式获取快捷shell图标?
- 4. 在intellij中切换到视图的任何快捷方式或快捷方式
- 5. 如何通过Win API配置快捷方式标题
- 6. PHP - 图像快捷方式
- 7. 快捷方式图标
- 8. 通过GPO的桌面快捷方式
- 9. 如何检测从“启动” - 文件夹快捷方式启动?
- 10. 如何创建链接到我的网站的桌面快捷方式/图标
- 11. WIX破损的快捷方式图标
- 12. 如何更改任务栏和快捷方式图标的运行时间?
- 13. 如何在快捷方式中使多个标签可点击?
- 14. 通过快捷方式运行JMeter?
- 15. 如何获得显示其“正常”图标的快捷方式?
- 16. 如何使用c#中的图标创建Internet快捷方式?
- 17. 如何更改sl4a脚本的快捷方式图标?
- 18. 在iOS上的网站快捷方式图标
- 19. Android:通过保存测试的快捷方式活动状态
- 20. 如何通过快捷方式在IdeaVim中打开类文件?
- 21. 如何在Windows中通过命令行创建快捷方式?
- 22. 如何通过python创建url快捷方式
- 23. 如何通过快捷方式打开灯泡?
- 24. 如何通过Innosetup删除桌面快捷方式
- 25. Android的安装快捷方式,但快捷方式图标不显示
- 26. 网站书签/快捷方式图标Android说明。不能得到通过标准丝带图标
- 27. 多个快捷方式图标?
- 28. 不显示快捷方式图标
- 29. Android动态快捷方式图标
- 30. 如何在rails中设置“快捷方式图标”?
只是解析网站的原始HTML响应..在原始字符串中寻找''link',搜索'rel =“icon”'然后在'href =“http中引用引号之间的值://example.com/myicon.png“ – 2011-04-26 12:48:29
”Google图标服务“ – mario 2011-04-26 12:54:46
我们是否可以接受? – 2011-06-02 14:15:04