Support Forums
Shorten URL - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: PHP The Hypertext Preprocessor (https://www.supportforums.net/forumdisplay.php?fid=21)
+---- Thread: Shorten URL (/showthread.php?tid=2688)



Shorten URL - zone - 11-08-2009

Credits and Source: http://www.roscripts.com/

Name: Shorten URL
Description: Shorten a long url with a function. Same feature thats on IPB and VB forum software.
Snippet:

PHP Code:
<?php
function shortenurl($url){
    
$length strlen($url);
    if(
$length 45){
        
$length $length 30;
        
$first substr($url0, -$length);
        
$last substr($url, -15);
        
$newurl $first."[ ... ]".$last;
        return 
$newurl;
    }else{
        return 
$url;
    }
}

$longurl "http://www.google.com/search?hl=en&client=firefox-a&channel=s&rls=org.mozilla%3Aen-US%3Aofficial&hs=BCR&q=metacafe&btnG=Search";
$shorturl shortenurl($longurl);
echo
"<a href=\"$longurl\">$shorturl</a>";
?>


Thankyou for reading. Be happy always Smile