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 中保留加号?
基础教程推荐
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
