splitting an url

Discussion in 'PHP' started by wizzard, Dec 7, 2006.

  1. #1
    Hello,

    I'm working via modrewrite to pass this:

    http://www.test.com/profile/123_text.html
    http://www.test.com/profile/text.html

    It goes toe prfile.php?id=123_text or prfile.php?id=text

    Now in my prfile script i want something that grabs out the 123 out of the id till the _ char.

    When there is no 123_ or 454_, ... then it must let the id like it is.

    Can someone helps me in here ?

    Ow and i'm sorry for my very bad english :(


    Cheers
    Kris
     
    wizzard, Dec 7, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    
    <?
    $url = "http://www.test.com/profile/123_text.html";
    preg_match("/[0-9]+_/", $url, $matches);
    echo "The number you're looking for is stored in . <br>" . '$matches[0]' . " : " . $matches[0];
    
    PHP:
     
    krakjoe, Dec 7, 2006 IP
  3. wizzard

    wizzard Peon

    Messages:
    160
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks mate :)
     
    wizzard, Dec 7, 2006 IP
  4. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #4
    always a pleasure.....
     
    krakjoe, Dec 7, 2006 IP
  5. Juls

    Juls Well-Known Member

    Messages:
    1,867
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    170
    #5
    I hope that you realize that you need to use that regex in your htaccess file for the mod-rewrite to work properly.

    you dont parse the url in the script, you parse it in htaccess and redirect it to the correct page, which then can do additional parsing of the formatted url.

    ;-)

    good luck.

     
    Juls, Dec 7, 2006 IP