Use PHP to implement short URL function

WBOY
Release: 2016-07-25 08:42:51
Original
1017 people have browsed it
  1. function shorturl($url){
  2. $length = strlen($url);
  3. if($length > 45){
  4. $length = $length - 30;
  5. $first = substr($url, 0, -$length);
  6. $last = substr($url, -15);
  7. $new = $first."[ ... ]".$last;
  8. return $new;
  9. }else{
  10. return $url;
  11. }
  12. }
  13. ?>
  14. // USAGE
  15. $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";
  16. $shorturl = shorturl($longurl);
  17. echo "$shorturl";
  18. ?>
复制代码

PHP


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template