Short URL Function with PHP


/ Published in: PHP
Save to your folder(s)

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](http://www.denizliozon.com) here.

Have a nice coding.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.