Let's say I request this url:
http://mydomain.com/script.php?var=2+2
$ _ GET ['var'] will now be: "2 2", where should be "2 + 2"
Obviously, I could encode the data before sending it and then decode it, but I wonder if this is the only solution. I could also replace spaces with plus characters, but I want to allow spaces as well. I just want any characters to be transmitted without any decryption or url encoding. Thank!
. $_SERVER["QUERY_STRING"], , URL %xx .
$_SERVER["QUERY_STRING"]
%xx
preg_match_all('/(\w+)=([^&]+)/', $_SERVER["QUERY_STRING"], $pairs); $_GET = array_combine($pairs[1], $pairs[2]);
( - % xx. .)
if(strpos($_SERVER["QUERY_STRING"], "+") !== false){ $_SERVER["QUERY_STRING"] = str_replace("+", "%2B", $_SERVER["QUERY_STRING"]); parse_str($_SERVER["QUERY_STRING"], $_GET); }
urlencode, . , + URL . "", "", , , . , + %2B, URL http://mydomain.com/script.php?var=2%2B2.
urlencode
+
%2B
http://mydomain.com/script.php?var=2%2B2
- URL-, + , , . A + (re: RFC2396 & sect; 3.4). +, %2B (re: RFC2396 & sect; 2.2).
"+" URL .
PHP Version 5.3.8
Echo:
2+2
:
<?php echo urlencode($_GET['var']); ?>
, .
Just replace your request parameter plus (+) with the character "% 2B" in the URL before requesting the URL.
Now you just get the query parameter. This will automatically replace "% 2B" with a plus sign.
I just used the urlencode()URL to encode correctly and urldecode($_Get())to use the string again.
urlencode()
urldecode($_Get())