tags:

views:

82

answers:

2

Im getting the URL using:

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

This returns something like:

http://me.domain.co.uk

How can I select 'me' only?

+1  A: 

Use parse_url, get the host of the URL and split it by dots. Then you can retrieve your desired subdomain easily.

Edit: Answered too fast, this is not the real answer to your problem, you could do that this way but i wouldn't do it. If you want the requested subdomain you can use something like that:

$hostParts = explode('.', $_SERVER['HTTP_HOST'])
print $hostParts[0];

Note that this example does not include error handling. (i.e.: $_SERVER['HTTP_HOST'] might be empty)

Malax
+1  A: 
$uriParts = explode('.',$_SERVER['SERVER_NAME']);

$subDomain = $uriParts[0];
VTEX
Note that $_SERVER['SERVER_NAME'] does not contain the host which was requested (HTTP Host header) which might not be what danit wants.
Malax