• Welcome to DNForum.com™ - Domain Sales, Domain Forum, Domain Appraisals, Domain Registrars
    If you are new to domains and looking to buy, sell and learn about domains then you have come to the right place. DNForum is the oldest global domain name community on the internet and continues to grow every day. There are over 45,000 domainers on DNForum doing everything from buying domains, selling domains, using our free in-house built tools, learning about domains and discussing domains. Take a minute and Register.

Wanted: Service Code to turn URL into Domain

Status
Not open for further replies.

Scooter

New Member
The Originals
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
 
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
 
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
 
easiest way is to use frame
 
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.
Back
Top Bottom