?
Solved

Extracting the first section of a url from a full address...

Posted on 2003-03-07
4
Medium Priority
?
177 Views
Last Modified: 2008-03-06
An easy one...
Using php I'd like to extract main section of a URL from the full address in the simplest way possible...

For example, getting 'www.leplop.com' from 'http://www.leplop.com/blah/anything/'

It preferably must work with any type of subdomain and TLD.

Regards,
Pip
0
Comment
Question by:le_plop
[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
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8088438
$_SERVER["SERVER_URL"];
0
 
LVL 32

Accepted Solution

by:
Batalf earned 200 total points
ID: 8088454
function findDomain($url){
  $url = str_replace("http://","",$url);
  $urlArray = explode("/",$url);
  $url = $urlArray[0];
  $urlArray = explode("?",$url);
  $url = $urlArray[0];
  return $url;
}

$url = "http://www.leplop.com/blah/anything/";
echo $url."<br>";
$url = findDomain($url);
echo $url."<br>";


 
0
 

Author Comment

by:le_plop
ID: 8088511
Quick simple response,
Thanks
Pip
0
 
LVL 5

Expert Comment

by:Lukasz Lach
ID: 8088530
oh, sure... stupid =)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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

800 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