irwan

PHP Function for Short URLs

Nov 15th, 2011
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php
  2. function shorturl($url){
  3.     $length = strlen($url);
  4.     if($length > 45){
  5.         $length = $length - 30;
  6.         $first = substr($url, 0, -$length);
  7.         $last = substr($url, -15);
  8.         $new = $first."[ ... ]".$last;
  9.         return $new;
  10.     }else{
  11.         return $url;
  12.     }
  13. }
  14. ?>
  15.  
  16.  
  17.  
  18. <?php
  19.  
  20. $longurl= "http://www.google.co.id/search?q=detik&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a";
  21. $shorturl = shorturl($longurl);
  22. echo "<a href=\"$longurl\">$shorturl</a>";
  23.  
  24. ?>
  25.  
Advertisement
Add Comment
Please, Sign In to add comment