开发者

get name from url

开发者 https://www.devze.com 2023-04-03 13:01 出处:网络
I have a function to get domain name from url <?php function getdomain($url) { $explode = e开发者_Go百科xplode(\".\", $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

精彩评论

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