![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Dec 2001
Posts: 7,952
|
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Industry Role:
Join Date: Dec 2002
Location: Behind the scenes
Posts: 5,190
|
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; $b = strpos($_SERVER['HTTP_HOST'], '.', $a+1); $site = substr($_SERVER['HTTP_HOST'], $a, $b-$a); basically this code finds first & second periods and copies anything between them to the new variable.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Dec 2002
Location: Behind the scenes
Posts: 5,190
|
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);
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Industry Role:
Join Date: Mar 2001
Location: Murrieta, CA
Posts: 3,620
|
Are you looking for _SERVER["SERVER_NAME"] ??
__________________
I buy plugs Skype: Due_Global /Due |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Mar 2001
Location: Murrieta, CA
Posts: 3,620
|
Ohhh you wanted it without .com/.net or whatever
$bla=$_SERVER["SERVER_NAME"]; $pieces = explode(".", $bla); echo "domain: $pieces[0]<br>extension $pieces[1]";
__________________
I buy plugs Skype: Due_Global /Due |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Dec 2001
Posts: 7,952
|
thanks
![]() That gave me more then 1 way to do it. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
ol' timer
Industry Role:
Join Date: Jan 2001
Location: Seattle WA
Posts: 4,715
|
you guys are dorks ;)
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Join Date: Feb 2002
Posts: 720
|
preg_match('/(?:www\.)*(.*?)\./', $_SERVER['HTTP_HOST'], $sitearr);
$site = $sitearr[1]; |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Join Date: Sep 2003
Posts: 708
|
![]()
__________________
"You can get more with a kind word and a gun than you can with a kind word alone.” |
![]() |
![]() ![]() ![]() ![]() ![]() |