View Single Post
Old 06-20-2009, 12:55 PM   #3 (permalink)
Sirupsen
The Contributor
 
Sirupsen's Avatar
 
Join Date: May 2009
Posts: 53
Thanks: 2
Sirupsen is on a distinguished road
Default

Hmm, I found this function on the intrawebs actually to get the url of the favicon: (As I'm pretty bad with regular expressions as well)
PHP Code:
    function get_ico_url()
    {
        if (
$this->ico_url == '')
        {
            
$this->ico_url $this->site_url 'favicon.ico';
       
            
# get html of page
            
$h = @fopen($this->site_url'r');
            if (
$h)
            {
                
$html '';
                while (!
feof($h) and !preg_match('/<([s]*)body([^>]*)>/i'$html))
                {
                    
$html .= fread($h200);
                }
                
fclose($h);

                
# search need <link> tag
                
if (preg_match('/<([^>]*)link([^>]*)(rel="icon"|rel="shortcut icon")([^>]*)>/iU'$html$out))
                {

                    
$link_tag $out[0];
                    if (
preg_match('/href([s]*)=([s]*)"([^"]*)"/iU'$link_tag$out))
                    {
                        
$this->ico_type = (!(strpos($link_tag'png')===false)) ? 'png' 'ico';
                        
$ico_href trim($out[3]);
                        if (
strpos($ico_href'http://')===false)
                        {
                            
$ico_href rtrim($this->site_url'/') . '/' ltrim($ico_href'/');
                        }
                        
$this->ico_url $ico_href;
                    }
                }
            }           
        }
        return 
$this->ico_url;
    } 
I guess I'd somehow get PHP to save this .ico file to a directory as you said Ryan, and check for duplicates.
Should be pretty easy to make a remote upload script which could handle that.

Edit:

Made a rather simple remote upload script:
PHP Code:
<?php
<?php
    
include('../_class/favicon.class.php');

    
$url 'http://twitter.com/';

    
$favicon = new favicon('http://twitter.com/'0);
    
$fv $favicon->get_ico_url();

    echo 
$fv;
    
    
$remote_file $fv;
    
    
preg_match('#^(?:http://)?([^/]+)#i'$url$matches);      
    
    
$name $matches[1];
    
    
$file_name $name.".ico";
    
$putdata fopen($remote_file"r");
    
$fp fopen($file_name"w");
    while (
$data fread($putdata102400))
      
fwrite($fp$data);
    
fclose($fp);
    
fclose($putdata);

?>

?>
Right now the name of this specific would be "twitter.com.ico" can someone help me fix the regular expression so it'll be "twitter.ico" only? Thanks!

Last edited by Sirupsen : 06-20-2009 at 01:57 PM.
Send a message via AIM to Sirupsen Send a message via MSN to Sirupsen Send a message via Yahoo to Sirupsen Send a message via Skype™ to Sirupsen
Sirupsen is offline  
Reply With Quote