Below the short php function to parse a URL and return just the domain name without using regex.
function
getDomain($url)
{
$exten="";
$explode =
explode(".", $url);
$firstpart = $explode[0];
$secondpart = $explode[1];
if(
!strstr($url,"www"))
// for url have www {
$secondpart=
explode("/",$secondpart);
$secondpart=$secondpart[0];
}
else
// not have www {
$thirdpart = $explode[2];
$thirdpart =
explode("/", $thirdpart);
$exten = ".".$thirdpart[0];
}
return $firstpart.".".$secondpart.$exten;
}
$domain=
getdomain("http://www.qualitypointtech.net/NewsFeed/view_allfeed.php");
$domain1=
getdomain("http://qualitypointtech.net/NewsFeed/view_allfeed.php");
the first one return the '
http://www.qualitypointtech.net' and second one return the '
http://qualitypointtech.net' as output.
so we need not worry about whether the url have www or not.