How to extract domain from a certain url

Discussion in 'PHP' started by PinoyIto, Jul 13, 2007.

  1. #1
    I am trying to create a script that will extract the domain from a certain URL but no success. For example of url is http://www.testurl.tld/page1/2 I want to extract the domain from that url so the result must be testurl.tld

    Thanks in advance
     
    PinoyIto, Jul 13, 2007 IP
  2. coderlinks

    coderlinks Peon

    Messages:
    282
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If the url is in $url, try doing:
    
    $domain = parse_url($url,PHP_URL_HOST);
    
    PHP:
    ~
    Thomas
     
    coderlinks, Jul 14, 2007 IP
    PinoyIto likes this.
  3. PinoyIto

    PinoyIto Notable Member

    Messages:
    5,863
    Likes Received:
    170
    Best Answers:
    0
    Trophy Points:
    260
    #3

    Thomas thanks mate that works perfectly...
     
    PinoyIto, Jul 14, 2007 IP