blob: 92ae119283aa348ffdb224242021f3e155d30f41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
Favicon fetcher
===============
Find and download the favicon
-----------------------------
```php
use PicoFeed\Favicon;
$favicon = new Favicon;
// The icon link is https://bits.wikimedia.org/favicon/wikipedia.ico
$icon_link = $favicon->find('https://en.wikipedia.org/');
$icon_content = $favicon->getContent();
```
PicoFeed will try first to find the favicon from the meta tags and fallback to the `favicon.ico` located in the website's root if nothing is found.
- `Favicon::find()` returns the favicon absolute url or an empty string if nothing is found.
- `Favicon::getContent()` returns the favicon file content (binary content)
When the HTML page is parsed, relative links and protocol relative links are converted to absolute url.
Check if a favicon link exists
------------------------------
```php
use PicoFeed\Favicon;
$favicon = new Favicon;
// Return true if the file exists
var_dump($favicon->exists('http://php.net/favicon.ico'));
```
Use personalized HTTP settings
------------------------------
Like other classes, the Favicon class support the Config object as constructor argument:
```php
use PicoFeed\Config;
use PicoFeed\Favicon;
$config = new Config;
$config->setClientUserAgent('My RSS Reader');
$favicon = new Favicon($config);
$favicon->find('https://github.com');
```
|