Is it possible to preserve plus signs in PHP $_GET

2019-01-15 19:04发布

Say I request this URL:

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

$_GET['var'] will now be: "2 2" where it should be "2+2"

Obviously I could encode the data before sending and then decode it, but I'm wondering if this is the only solution. I could also replace spaces with plus symbols, but I want to allow spaces as well. I simply want whatever characters were passed, without any url decoding or encoding going on. Thank you!

标签: php encoding get
7条回答
在下西门庆
2楼-- · 2019-01-15 19:50

Whomever is generating the URL containing a + in the query segment is wrong unless they intend it to represent a space character. A + in the query is a reserved character (re: RFC2396 §3.4). If you need to insert a literal + in the query string, then it must be encoded as %2B (re: RFC2396 §2.2).

查看更多
登录 后发表回答