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

It's for getting the favicon from a webpage (no matter where it's located, no matter which page there so www.youtube.com/d8Ud2 works as good as youtube.com), remote uploading this favicon to my own server so I won't leech their bandwith. If the file is 7 days < old, it's deletes the file and uploads a new one. Basically I got my script looking like this about an hour ago:

PHP Code:
<?php
    
include('../_class/favicon.class.php');

if (
$_POST['url']) {
    
$url $_POST['url'];

    
$favicon = new favicon("$url"0);
    
$fv $favicon->get_ico_url();
    
    
$remote_file $fv;
    
    
preg_match('#^(?:http://)?([^/]+)#i'$url$matches);      
    
    
$name $matches[1];
    
    
$file_name $name.".ico";
    
$file_age date("U"filectime($file_name));
    
$now date("U");
    
$file_difference $now $file_age;
    
    
// The page title
    
$file file($url);
    
$file implode("",$file);
    
    if (!
file_exists($file_name)) {
           
$putdata fopen($remote_file"r");
        
$fp fopen($file_name"w");
        while (
$data fread($putdata102400))
          
fwrite($fp$data);
        
fclose($fp);
        
fclose($putdata);
        
        echo 
"Wow, cool! Your the first one to use that website.<br>";
        
    } if (
$file_difference '604800') {
        
unlink($file_name);
        
           
$putdata fopen($remote_file"r");
        
$fp fopen($file_name"w");
        while (
$data fread($putdata102400))
          
fwrite($fp$data);
        
fclose($fp);
        
fclose($putdata);
    } else {
    }
    
    echo 
'<br/><img src="http://slimpl.com/beta/user/'.$file_name.'" />';
    if(
preg_match('#^(?:http://)?([^/]+)#i'$url$m)) {
        echo 
" <b>";
        echo 
ucfirst($m[1]);
        echo 
"</b>"n
    
}
    echo 
"<br><br>";
}
?>
Add a new website about you!<br>
<form method="post" action="">
<input type="test" name="url">
<input type="submit">
</form>
1 thing I however need some help with right now is:

PHP Code:
    if(preg_match('#^(?:http://)?([^/]+)#i'$url$m)) {
        echo 
" <b>";
        echo 
ucfirst($m[1]);
        echo 
"</b>"n
    

I'd like this to only return the name of the domain, and not the last ".com" or ".org" or dot whatever. So for example if $url = 'http://twitter.com'; it'll output: Twitter.

Something else is that if the user puts in: http://www.twitter.com it'll create: www.twitter.com.ico, however if he inputs http://twitter.com it'll create twitter.com.ico, how would I fix it so it'll make the http://twitter.com url to http://www.twitter.com, or just require the user to use www adresses as most websites supports this?

This all is regular expressions, which I'm still in the proccess of learning, so I'd love some help on those topics.
Hope that this was all understandable!

Edit: It's all fixed due to awesome Bruja and Salethe on IRC! Here's the expression: http://slexy.org/view/s20e2YvBPt

Last edited by Sirupsen : 06-20-2009 at 11:14 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