Welcome Guest, Not a member yet? Register   Sign In
Acquire the url prefix?
#1

[eluser]coldscooter[/eluser]
Is there any nice way of detecting the url prefix?

so for this url:

http://test.mysite.com

I would like to extract 'test'
#2

[eluser]CroNiX[/eluser]
They're "subdomains", not "prefixes". This will probably work, but it will only return the first subdomin. For instance, if your url was http://some.subdomain.domain.com, it would only return "some". If there isn't a subdomain, like http://domain.com, it will return boolean FALSE.
Code:
function get_subdomain($url)
{
  $parts = parse_url($url);
  $parts = explode('.', $parts['host']);
  return (count($parts) > 2) ? $parts[0] : FALSE;
}

$subdomain = get_subdomain('http://test.domain.com');
var_dump($subdomain);
// "test"

$subdomain = get_subdomain('http://domain.com');
var_dump($subdomain);

// (bool)FALSE
#3

[eluser]CroNiX[/eluser]
Strange, the forum software is inserting commas where there are none.




Theme © iAndrew 2016 - Forum software by © MyBB