Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

Wanted: Service Code to turn URL into Domain

Status
Not open for further replies.

Scooter

Level 3
Legacy Platinum Member
Joined
Jan 1, 2003
Messages
61
Reaction score
0
I am looking for a bit of code for a PHP page.

I want to be able to turn any URL string into a domain name with all the extra crap removed.

Examples:
From URL String: http://www.any-domain.com/contact.php
into domain: any-domain.com

or URL String: http://www.any-domain.co.uk/dir/page.php
into domain: any-domain.co.uk


Thanks
:)

Edit: fix examples
 
Dynadot - Expired Domain Auctions

Nexus

DNF Addict
Legacy Exclusive Member
Joined
Sep 11, 2002
Messages
1,495
Reaction score
0
This is a nice site that has a set of useful regular expressions for all sorts of purposes. I modified one from their URI section.
http://www.regexlib.com/DisplayPatterns.aspx?cattabindex=1&categoryId=2

Here's the code:
Code:
$str = "http://www.any-domain.co.uk/dir/page.php";
$regex = "[a-zA-Z0-9]+[\.]?(([a-zA-Z0-9\.\-]+)?\.(com|org|net|mil|edu|co.uk))";
eregi($regex,$str,$grab);
echo $grab[1];
Should get the job done... just add any other extensions you want to check for.

RETURN 1: any-domain.co.uk
RETURN 2: any-domain.com

~ Nexus
 

Nexus

DNF Addict
Legacy Exclusive Member
Joined
Sep 11, 2002
Messages
1,495
Reaction score
0
I was testing something and I came up with this (which might also be useful to you). The following PHP code will take an external text document, and return a list of all the domains it finds in it.
Code:
$myfile = file("C:/sample.txt");
$myfile = addslashes(implode("",$myfile));
$regex = "/([a-z0-9]+[\.])?(([a-z0-9\.-]+)\.(com|org|net|mil|edu|co.uk))/i";
preg_match_all($regex,$myfile,$grab);
while(list($key,$value) = each($grab[2])) echo $value."<br>";
The following will alphabetize the list and remove duplicates.
Code:
$myfile = file("C:/sample.txt");
$myfile = addslashes(implode("",$myfile));
$regex = "/([a-z0-9]+[\.])?(([a-z0-9\.-]+)\.(com|org|net|mil|edu|co.uk))/i";
preg_match_all($regex,$myfile,$grab);
$final = $grab[2];
asort($final);
reset($final);
$temparr=$final;
 while(list($key,$value) = each($final))
 {
   if(!empty($prevkey))
     if($value==$final[$prevkey]) unset($temparr[$key]);
   $prevkey = $key;
 }
$final = $temparr;
while(list($key,$value) = each($final)) echo strtolower($value)."<br>";
You can use the DNAuction page html as a test sample:
http://www.dnfauctions.com/auction/auction.cgi?category=domains1&listtype=current

Best Regards,
~ Nexus
 

.com.net.org

Level 8
Legacy Platinum Member
Joined
Oct 20, 2002
Messages
1,951
Reaction score
0
easiest way is to use frame
 

Whois-Search

Level 9
Legacy Platinum Member
Joined
Apr 28, 2002
Messages
3,119
Reaction score
1
just use the built in php function
parse_url ( string url), it will seperate your url in to a component array; for the current page use: parse_url ( $PHP_SELF).
The important array components will be:
[host]: www.your_domain
and [path]: somepage.php.
So just strip out the www. from the host with a reg exp.

If interested in a javascript version, see a similiar script to expose just the domain name on mouseover, at http://www.choicenames.com/linkstripper.html, should be easy to break the script down to return just what you want to see.
 
Status
Not open for further replies.

Who has viewed this thread (Total: 1) View details

Who has watched this thread (Total: 1) View details

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members Online

Sedo - it.com Premiums

IT.com

Premium Members

MariaBuy

Upcoming events

New Threads

Our Mods' Businesses

UrlPick.com

*the exceptional businesses of our esteemed moderators

Top Bottom