![]() |
Php help needed...
Is there a better way to get this other then doing it in 2 steps?
$site = preg_replace ('#www.#is', '', $_SERVER['HTTP_HOST']); $site = preg_replace ('#.com#is', '', $site); I want just the parts inbetween www and the last . where its .com/.net etc. Thanks |
one line:
$site = substr($_SERVER['HTTP_HOST'], strpos($_SERVER['HTTP_HOST'], '.')+1, strpos($_SERVER['HTTP_HOST'], '.', $a+1)-strpos($_SERVER['HTTP_HOST'], '.')+1); the same as above but more readable: Code:
$a = strpos($_SERVER['HTTP_HOST'], '.')+1; basically this code finds first & second periods and copies anything between them to the new variable. |
a bit of mix up in the above post for one liner, heres the correct one:
$site = substr($_SERVER['HTTP_HOST'], strpos($_SERVER['HTTP_HOST'], '.')+1, strpos($_SERVER['HTTP_HOST'], '.', (strpos($_SERVER['HTTP_HOST'], '.')+1)+1)-strpos($_SERVER['HTTP_HOST'], '.')+1); or $domain = $_SERVER['HTTP_HOST']; $site = substr($domain, strpos($domain, '.')+1, strpos($domain, '.', (strpos($domain, '.')+1)+1)-strpos($domain, '.')+1); |
Are you looking for _SERVER["SERVER_NAME"] ??
|
Ohhh you wanted it without .com/.net or whatever
$bla=$_SERVER["SERVER_NAME"]; $pieces = explode(".", $bla); echo "domain: $pieces[0]<br>extension $pieces[1]"; |
thanks :)
That gave me more then 1 way to do it. |
you guys are dorks ;)
|
preg_match('/(?:www\.)*(.*?)\./', $_SERVER['HTTP_HOST'], $sitearr);
$site = $sitearr[1]; |
|
All times are GMT -7. The time now is 07:12 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123