We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How do I pull the subdomain name out of a URL?

Donnie Walker
on
Medium Priority
330 Views
Last Modified: 2012-05-07
How would I get the subdomain name from a web address?

For example, in http://subdomain.domain.com how would I grab the name subdomain from the URL?

Comment
Watch Question

Most Valuable Expert 2011
Author of the Year 2014

Commented:

// BREAK THE HOST NAME APART AT THE DOTS
$x = explode('.', $_SERVER["HTTP_HOST"]);
$subdomain = $x[0];

Open in new window

Most Valuable Expert 2011
Author of the Year 2014
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
As always Ray, Thanks.
Most Valuable Expert 2011
Author of the Year 2014

Commented:
Thanks for the points - glad I could help, ~Ray
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.