当前位置:Gxlcms > PHP教程 > 利用PHP实现短网址功能

利用PHP实现短网址功能

时间:2021-07-01 10:21:17 帮助过:27人阅读

  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

人气教程排行