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.
精彩评论