Extract domain name

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shabam

    Extract domain name

    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 ".


  • David Kroeber

    #2
    Re: Extract domain name

    * Shabam:[color=blue]
    > 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 ".[/color]

    try something like:

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

    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

    Comment

    • Andrew Tkachenko

      #3
      Re: Extract domain name

      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:
      [color=blue]
      > 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 ".[/color]

      --
      Andrew

      Comment

      Working...