php - Usage of "+" in array - php
问题描述
I want to write a php script which redirects to different ".txt" documents by visiting the page "http://example.com/script.php" - for example my script for "http://example.com/script.php?data=ABC+DEF". I got that far:
<?php
$targets = array("ABC+DEF" => "test.txt" /*, more redirects.. not the only one i have */ );
if (isset($_GET["data"]) && array_key_exists($_GET["data"], $targets)) {
header("Location: {$targets[$_GET["data"]]}");
exit;
?>
The issue is that it doesn't work if there is a + character in the array(""); but it works with a -.
That means "http://example.com/script.php?data=ABCDEF" would work
also "http://example.com/script.php?data=ABC-DEF" works.
Only http://example.com/script.php?data=ABC+DEF does not work.
Do I have to mark the + with a slahsh or '+' for it to work? I'm just braindamaged rightnow and not getting anywhere at this point. Probably easy to fix with two characters. Thanks for your help.
Edit: Yeah I was braindead, fixed it without even urlencode. Since I don't want to change or encode the url somehow I just leave a blank space between ABC DEF instead of using the + so it looks like this now:
array("ABC DEF" => "test.txt");
解决方案
You need to use the URL encoded character for the +
, which is %2B
, as without being encoded it is interpreted as a space by many web browsers
推荐阅读
- python - 请求返回相同的数据
- python - 如何在python中删除图表中的空格?
- mongodb - 无法连接到 MongoDB Atlas
- sql - 使用单个查询更新并插入表中
- android - Algolia 的 xml 的“属性”引发编译错误
- javascript - 如何将 Firebase Callables 与 PWA 离线功能结合使用?
- python - 如何在某个未知索引处对字符串输入进行切片
- module - 禁用模块后,Magento2 模块字段在管理员中仍然可见
- powershell - 如何在 Powershell 中使用 OCSP 地址测试证书验证
- pdf - convertapi pdf to image:指定页面范围