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:
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
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
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
<?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: