Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to get favicon with Goutte php

function getFavicon($url){
    # make the URL simpler
    $elems = parse_url($url);
    $url = $elems['scheme'].'://'.$elems['host'];

    # load site
    $output = file_get_contents($url);

    # look for the shortcut icon inside the loaded page
    $regex_pattern = "/rel="shortcut icon" (?:href=['"]([^'"]+)['"])?/";
    preg_match_all($regex_pattern, $output, $matches);

    if(isset($matches[1][0])){
        $favicon = $matches[1][0];

        # check if absolute url or relative path
        $favicon_elems = parse_url($favicon);

        # if relative
        if(!isset($favicon_elems['host'])){
            $favicon = $url . '/' . $favicon;
        }

        return $favicon;
    }

    return false;
}
Comment

PREVIOUS NEXT
Code Example
Php :: php edit link 
Php :: laravel eloquent get x number of results 
Php :: truncate url rewrites magento 2 database 
Php :: uft8 json php 
Php :: install composer laravel 
Php :: How to create routes in the codeigniter 
Php :: Laravel Nested whenLoaded 
Php :: no cache hummingbird 
Php :: laravel update only changed fields 
Php :: How do I display logged-in username IF logged-in? site:wordpress.stackexchange.com 
Php :: how to removde product into shop loop via product id 
Php :: apt-get install php wordpress extensions 
Php :: limit wordpress search to title 
Php :: is search page wordpress dev 
Php :: single sign on php script 
Php :: laravel-check-if-related-model-exists 
Php :: woocommerce_product_is_on_sale filter 
Php :: laravel database engine innodb 
Php :: Error : Call to undefined method IlluminateNotificationsChannelsMailChannel::assertSentTo() 
Php :: laravel blade multiple can 
Php :: php session destroy not working 
Php :: add a snippet in twig shopware 6 
Php :: laravel 8 model filter 
Php :: laravel how to check app env 
Php :: php get api 
Php :: php array remove the last element 
Php :: make model factory and controller laravel 
Php :: php convert accented characters to html entities 
Php :: Laravel unique cheque using multiple column 
Php :: php unit test 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =