?
Solved

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

Posted on 2009-06-29
4
Medium Priority
?
318 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?

0
Comment
Question by:Donnie Walker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24738062

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

Open in new window

0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 24738074
If you have a separate URL in your code, first explode on the // to isolate the information that is in $_SERVER["HTTP_HOST"]
$url = 'http://subdomain.domain.com'
$x = explode('//', $url);
$host = $x[1];
 
$x = explode('.', $host);
$subdomain = $x[0];

Open in new window

0
 

Author Closing Comment

by:Donnie Walker
ID: 31598019
As always Ray, Thanks.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 24739908
Thanks for the points - glad I could help, ~Ray
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question