1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to trim php string?

Discussion in 'PHP' started by Mr. Pimp, Aug 31, 2009.

  1. #1
    Hello
    I have string as :
    $string="/inbox/?rfbafefaa&r3b54c457&compose&ids=645976873&refid=5";

    Lets say i wanna capture only 645976873 (Its in ids=645976873) in some variable.
    Can anyone tell me how to do that?
    Its a simple string. and generated randomly everytime. Every field will have randing numbers (/inbox/?r, &compose, &ids, &refid words always gunna b there in string) .
    I wanna know how do capture string contents starting from specific word till specific ending word?

    (P.S. Its a string and not received from any form etc. So please dont suggest me $_GET['ids'])
     
    Mr. Pimp, Aug 31, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    if (preg_match('/ids=([0-9]+)/', $string, $match)) {
       echo $match[1];
    }
    
    PHP:
     
    premiumscripts, Aug 31, 2009 IP
  3. alons

    alons Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    parse_str($str);
    echo $ids;
    
    PHP:
    This is meant for parsing query strings like yours
     
    alons, Aug 31, 2009 IP
  4. Mr. Pimp

    Mr. Pimp Active Member

    Messages:
    142
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #4
    Thanks a lot for your replies.
    That did the trick... worked perfectly ;)

    thanks a million :eek:
     
    Mr. Pimp, Aug 31, 2009 IP