Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Extract domain name

Reply
Thread Tools

Extract domain name

 
 
Shabam
Guest
Posts: n/a
 
      11-12-2004
How do you fetch just the domain name part of a variable in a script? The
variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
"http://sub.domain.com/blahblah/whatever/page.htm".

What I need is to extract just the "domain.com".


 
Reply With Quote
 
 
 
 
David Kroeber
Guest
Posts: n/a
 
      11-12-2004
* Shabam:
> How do you fetch just the domain name part of a variable in a script? The
> variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
> "http://sub.domain.com/blahblah/whatever/page.htm".
>
> What I need is to extract just the "domain.com".


try something like:

my(undef, undef, $domain) = $s =~
/^(http|ftp|whatever):\/\/(www|ftp|whatever)\.(.+?)\//;

There might be some module that does what you're looking for (check
CPAN), I didn't look for it, actually...

bye
//Dave

--
Ja, der typische "Ich tippe alles ein was mir ein paar Trottel aus dem
IRC sagen"-Newbie wird aber kein Solaris nutzen...
-- Christoph Gebhardt in bjt
 
Reply With Quote
 
 
 
 
Andrew Tkachenko
Guest
Posts: n/a
 
      11-12-2004
Look for URI module. IMHO, its a good and simple thing for parsing URLs

use URI;
($domain = URI->new("http://www.domain.com/blahblah/whatever/page.htm")->authority) =~ s/^www\.//i


Regards,
Andrew

Shabam wrote on 12 Ноябрь 2004 16:02:

> How do you fetch just the domain name part of a variable in a script? The
> variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
> "http://sub.domain.com/blahblah/whatever/page.htm".
>
> What I need is to extract just the "domain.com".


--
Andrew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to extract domain name without sub domain from url Chem Leakhina Ruby 2 06-23-2009 09:11 AM
Making a server on one domain the domain controller of a new domain Limited Wisdom MCSA 7 09-13-2006 02:18 AM



Advertisments