“的用法+&引用;数组中的php

“的用法+&引用;数组中的php,php,html,arrays,Php,Html,Arrays,我想编写一个php脚本,通过访问“”页面重定向到不同的“.txt”文档-例如,我的“”脚本。 我走了那么远: <?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("L

我想编写一个php脚本,通过访问“”页面重定向到不同的“.txt”文档-例如,我的“”脚本。 我走了那么远:

<?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;
?>

我建议您在生成url时使用函数,然后

您需要为
+
使用url编码字符,即
%2B
,因为许多web浏览器在未编码的情况下会将其解释为空格

我建议在url中添加斜杠,或使用urlencode。Apache通常将
+
视为空格而不是字符;e、 g:JS
encodeURIComponent('ABC+DEF')
产生了
“ABC%2BDEF”
。这将如何解决问题?存在就是为了这个目的。
array("ABC DEF" => "test.txt");