Help with php

Discussion in 'PHP' started by blue_angel, Dec 3, 2006.

  1. #1
    blue_angel, Dec 3, 2006 IP
  2. koolasia

    koolasia Banned

    Messages:
    1,413
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    0
    #2
    koolasia, Dec 3, 2006 IP
  3. papa_face

    papa_face Notable Member

    Messages:
    2,237
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    285
    #3
    The OP simply wants to get rid of the "/test1/test2" in a given domain name. So he/she is left with the name domain name "example.com".

    I have tried to come up with something to do that, but I'm having a little difficulty.
     
    papa_face, Dec 3, 2006 IP
  4. Nikolas

    Nikolas Well-Known Member

    Messages:
    1,022
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    150
    #4
    
    $url = 'http://www.demourl.com/test1/test2';
    $parts = parse_url($url);
    echo 'http://' . $parts['host'] . '/';
    
    PHP:
     
    Nikolas, Dec 3, 2006 IP
    klown likes this.
  5. klown

    klown Peon

    Messages:
    2,093
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    <?php
    // get host name from URL
    preg_match('@^(?:http://)?([^/]+)@i',
       "http://www.php.net/index.html", $matches);
    $host = $matches[1];
    
    // get last two segments of host name
    preg_match('/[^.]+\.[^.]+$/', $host, $matches);
    echo "domain name is: {$matches[0]}\n";
    ?>
    
    PHP:
    The above example will output:

    domain name is: php.net
     
    klown, Dec 3, 2006 IP
  6. blue_angel

    blue_angel Well-Known Member

    Messages:
    1,174
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #6
    Thanks a lot all of you for your answers They helped me a lot.
     
    blue_angel, Dec 3, 2006 IP