Strip String

Discussion in 'PHP' started by encom, Sep 18, 2009.

  1. #1
    If I have the string:
    $url = 'info.php?id=24&c=2'
    PHP:
    How can I echo out the id (in this case 24)
     
    encom, Sep 18, 2009 IP
  2. Oli3L

    Oli3L Active Member

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    70
    #2
    you can simply use $_GET['id'] if you have it in your URL address.

    You can do this too:
    
    
    $url = 'info.php?id=24&c=2'
    $matchess = preg_match("#id=(.*?)&#is",$url,$matches);
    
    $id = $matches[1];
    
    
    PHP:
    (I wrote that in 1 minute so I'm sorry if it's not working like you want)
     
    Oli3L, Sep 18, 2009 IP
  3. encom

    encom Member

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    GET is not what I am looking for, because $url is not the url of the page.

    BUT thanks, the second code is exactly what I am looking for. :)
     
    encom, Sep 19, 2009 IP