Query string with 2 same variables?

Discussion in 'PHP' started by ridesign, Apr 20, 2010.

  1. #1
    I have a query string with 2 variables with the same name and I want to get the value of the first variable m=: I want to get m="noodles"
    query string:
    ?m=noodles&a=http://www.noodlesite.com?refid=ena_&s=d5h&cid=HDEna&dgc=IR&lid=SHP_BK1&m=abc

    I am using the php code below, but I get m=abc instead of m=noodles:
    
    $url = "?m=noodles&a=http://www.noodlesite.com?refid=ena_&s=d5h&cid=HDEna&dgc=IR&lid=SHP_BK1&m=abc"
    parse_str($url, $myArray);
    $m = $myArray['m'];
    
    PHP:
     
    ridesign, Apr 20, 2010 IP
  2. devidhood

    devidhood Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hiiiii

    Accroding to me query string with 2 same variable its possible but only 1 query string will work.why dont try 2 different query string to get variable.

    Regards
    devid
     
    devidhood, Apr 21, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Hi,

    That is bad programming - You should urlencode the URL you are passing in the query string..... which also means you wont have that problem.

    http://php.net/manual/en/function.urlencode.php
     
    lukeg32, Apr 21, 2010 IP
  4. HiMyNameIsErez

    HiMyNameIsErez Greenhorn

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #4
    Try to encode your url with urlencode($url) function,should work perfectly
     
    HiMyNameIsErez, Apr 21, 2010 IP
  5. ridesign

    ridesign Peon

    Messages:
    294
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I can not encode a=http://www.noodlesite.com bit because the query string has been entered like that into the database, and if I encode $url then the whole thing is encoded, and I still will not get the first m=noodles
     
    ridesign, Apr 21, 2010 IP
  6. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #6
    <?php
    $url = "?m=noodles&a=http://www.noodlesite.com?refid=ena_&s=d5h&cid=HDEna&dgc=IR&lid=SHP_BK1&m=abc";
    parse_str($url, $myArray);
    $m = $myArray['?m'];
    //output: noodles
    echo $m;
    ?>
    PHP:
     
    danx10, Apr 21, 2010 IP
  7. ridesign

    ridesign Peon

    Messages:
    294
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks danx10
     
    ridesign, Apr 22, 2010 IP