Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2003-03-07
4
Medium Priority
?
179 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
  • 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

This article discusses how to create an extensible mechanism for linked drop downs.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses

581 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