Is it possible to save plus signs in PHP $ _GET without encoding?

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!

+5
source share
7 answers

. $_SERVER["QUERY_STRING"], , URL %xx .

preg_match_all('/(\w+)=([^&]+)/', $_SERVER["QUERY_STRING"], $pairs);
$_GET = array_combine($pairs[1], $pairs[2]);

( - % xx. .)

+4
if(strpos($_SERVER["QUERY_STRING"], "+") !== false){
    $_SERVER["QUERY_STRING"] = str_replace("+", "%2B", $_SERVER["QUERY_STRING"]);
    parse_str($_SERVER["QUERY_STRING"], $_GET);
}
+5

urlencode, . , + URL . "", "", , , . , + %2B, URL http://mydomain.com/script.php?var=2%2B2.

+2

- URL-, + , , . A + (re: RFC2396 & sect; 3.4). +, %2B (re: RFC2396 & sect; 2.2).

+1

"+" URL .

PHP Version 5.3.8

http://mydomain.com/script.php?var=2+2

Echo:

2+2

:

<?php
echo urlencode($_GET['var']);
?>
0

, .

  • 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.

0
source

I just used the urlencode()URL to encode correctly and urldecode($_Get())to use the string again.

0
source

All Articles