开发者

get name from url

I have a function to get domain name from url

 <?php
 function getdomain($url)
 {
  $explode = e开发者_Go百科xplode(".", $url);
  $tld = $explode[1];
  $tld = explode("/", $tld);
  $name = $explode[1];
  print("$tld[0]");
 }

 print(getdomain("aa.namepros.aaa.com/showthread.php?p=350493"));


?>

It works fine for me, but if a user only entered

 print(getdomain("namepros"));

then, it shows me error.


You are reinventing the square wheel. This is a common problem, so common that it's been solved ages ago and added to PHP's standard library:

http://www.php.net/manual/en/function.parse-url.php

Do yourself a favor and use what's there instead of hurting yourself.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜