Posted By

jackoder on 05/20/10


Tagged

url php short


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

eval


Short URL Function with PHP


 / Published in: PHP
 

Dear php coders,

Here's a code block that you can use in your projects to get shorter long urls.

Also recommend these articles about ozon tedavisi here.

Have a nice coding.

  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. // USAGE
  17.  
  18. <?php
  19.  
  20. $longurl= "http://www.google.com/search?q=symfony+project&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:tr:official&client=firefox-a";
  21. $shorturl = shorturl($longurl);
  22. echo "<a href=\"$longurl\">$shorturl</a>";
  23.  
  24.  
  25. ?>

Report this snippet  

You need to login to post a comment.