PHP code example of php-feed-io / favicon-io

1. Go to this page and download the library: Download php-feed-io/favicon-io library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

php-feed-io / favicon-io example snippets


use FeedIo\FaviconIo\FaviconDiscovery;
use Nyholm\Psr7\Factory\Psr17Factory;
use Symfony\Component\HttpClient\Psr18Client;

$psr17Factory = new Psr17Factory();
$httpClient   = new Psr18Client();

$discovery = new FaviconDiscovery(
    httpClient:     $httpClient,
    requestFactory: $psr17Factory,
);

$faviconUrl = $discovery->discover('https://example.com');
// Returns a URL string, or null if no favicon was found.

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Psr16Cache;

$cache = new Psr16Cache(new FilesystemAdapter());

$discovery = new FaviconDiscovery(
    httpClient:     $httpClient,
    requestFactory: $psr17Factory,
    cache:          $cache,           // PSR-16 CacheInterface
    cacheTtl:       7 * 86400,        // seconds; default is 7 days
);

$discovery = new FaviconDiscovery(
    httpClient:     $httpClient,
    requestFactory: $psr17Factory,
    logger:         $psrLogger,       // PSR-3 LoggerInterface
);