是否可以在PHP $ _GET vars中保存加号而不进行编码? [英] Is it possible to preserve plus signs in PHP $_GET vars without encoding?
问题描述
请问这个网址:
http://mydomain.com/script.php?var=2+2
$ _ GET ['var']现在将是: 2 2其中应该是2 + 2
$_GET['var'] will now be: "2 2" where it should be "2+2"
显然,我可以在发送之前对数据进行编码,然后对其进行解码,但我想知道这是否是只有解决方案我也可以用加号替换空格,但我也想允许空格。我只想要任何字符被传递,没有任何url解码或编码。谢谢!
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!
推荐答案
当然。你可以读出 $ _ SERVER [QUERY_STRING]
,分解自己,然后放弃通常的URL解码,或者只转换%xx
placeholder back。
Of course. You could read out $_SERVER["QUERY_STRING"]
, break it up yourself, and then forgo the usual URL decoding, or only convert %xx
placeholders back.
preg_match_all('/(\w+)=([^&]+)/', $_SERVER["QUERY_STRING"], $pairs);
$_GET = array_combine($pairs[1], $pairs[2]);
(示例仅适用于字母数字参数,不执行上述的%xx解码。原始输入。)
(Example only works for alphanumeric parameters, and doesn't do the mentioned %xx decoding. Just breaks up the raw input.)
这篇关于是否可以在PHP $ _GET vars中保存加号而不进行编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!