GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Php help needed... (https://gfy.com/showthread.php?t=453454)

4Pics 04-07-2005 09:38 PM

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

Serge Litehead 04-07-2005 10:19 PM

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.

Serge Litehead 04-07-2005 10:24 PM

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);

Due 04-07-2005 11:10 PM

Are you looking for _SERVER["SERVER_NAME"] ??

Due 04-07-2005 11:16 PM

Ohhh you wanted it without .com/.net or whatever
$bla=$_SERVER["SERVER_NAME"];
$pieces = explode(".", $bla);
echo "domain: $pieces[0]<br>extension $pieces[1]";

4Pics 04-08-2005 12:04 AM

thanks :)

That gave me more then 1 way to do it.

BrettJ 04-08-2005 12:23 AM

you guys are dorks ;)

AgentCash 04-08-2005 12:28 AM

preg_match('/(?:www\.)*(.*?)\./', $_SERVER['HTTP_HOST'], $sitearr);
$site = $sitearr[1];

AlCapone 04-08-2005 01:39 AM

http://www.w3bdevil.com/forums/NM-Jiggawatts2.jpg


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