Need to strip url and leave just host url

Discussion in 'PHP' started by schmidte, Dec 26, 2007.

  1. #1
    Example:
    I need to strip this url: www.example.com/dir1/dir2/page.html
    to
    www.example.com


    I'm trying to link to the site analytics page at Compete.com for each result in my search engine
    ( www.GoLexa.com ). However it will only accept the host url with nothing past the extension.

    Here's and acceptable call:
    http://siteanalytics.compete.com/www.cnn.com/

    This would not be acceptable:
    http://siteanalytics.compete.com/www.cnn.com/news.html


    Here's what I currently have to make a call to Compete.com, I've stripped off the http:// leaving the url starting with www:
    http://siteanalytics.compete.com/".str_replace("http://", "", $val['redirecturl'])."
    This works fine as long as there's nothing past the extension.

    This is my variable: ".str_replace("http://", "", $val['redirecturl'])."

    Thanks,
    ED
     
    schmidte, Dec 26, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hogan_h, Dec 26, 2007 IP
  3. tonybogs

    tonybogs Peon

    Messages:
    462
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The contents of the $_SERVER['SERVER_NAME'] variable might be all that you need.

    Hope this helps
     
    tonybogs, Dec 26, 2007 IP
  4. brianng

    brianng Active Member

    Messages:
    171
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    try this

    $url = "www.example.com/dir1/dir2/page.html"
    $url2 = explode("/", $url);

    echo $url2[0];
     
    brianng, Dec 26, 2007 IP