- Forums
- PHP
- How To Get Domain Names With Php Without Www.
This Page Contains information about How To Get Domain Names With Php Without Www. By Wallpaperama in category PHP with 4 Replies. [1206], Last Updated: Sat May 18, 2024
Wallpaperama
Wed Nov 12, 2008
4 Comments
2697 Visits
ok, if you are reading my post here its because you want to know how you can get the current domain name with php but without the www part. well, www is the host name and the TLD is the domain name..
so for example, lets use www.wallpaperama.com you are currently visiting www.wallpaperama.com and i want to remove the www. part, so this is how my php code would look like
$domain = "$_SERVER['HTTP_HOST']";
echo $domain;
OUTPUT: www.wallpaperama.com
now this is how i would remove the www part:
$domain = str_replace("www.","", $_SERVER['HTTP_HOST']);
echo $domain;
OUTPUT: wallpaperama.com
as you can see i removed the www. part with the str_replace() function from php, this way it will only show or display the TLD and not the hostname (www)
hope this helps