Reputation: 10366
$hostname = "abc.domain.com"
I just want "abc" and nothing after it.
Upvotes: 0
Views: 436
Reputation: 816442
$host = substr($hostname, 0, strpos($hostname, '.'));
or maybe better, strstr
:
$host = strstr($hostname, '.', true);
There are a lot of functions available to process strings.
Upvotes: 2
Reputation: 21466
Will it always have a subdomain?
If so, you can just do
$parts = explode('.', $hostname);
$subdomain = $parts[0];
If there might not be a subdomain
$parts = explode('.', $hostname);
$subdomain = count($parts) == 3 ? $parts[0] : NULL;
Upvotes: 1
Reputation: 318508
Use explode()
:
$parts = explode('.', $hostname);
// $parts[0]
Upvotes: 1