Is it possible to preserve plus signs in PHP $_GET vars without encoding?(是否可以在没有编码的情况下在 PHP $_GET vars 中保留加号?)
问题描述
假设我请求此 URL:
Say I request this URL:
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
占位符转换回来.
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 中保留加号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以在没有编码的情况下在 PHP $_GET vars 中保留加号?


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01