Php 发送get请求时正在转换具有特殊字符的参数

Php 发送get请求时正在转换具有特殊字符的参数,php,Php,我面临一个问题。我通过restapi发送数据,并使用PHP接受参数值。我在下面解释我的代码 if($action==11){ $query=$_SERVER['QUERY_STRING']; $result=between('searchKey=', '&', $query); echo $result; } function after ($this, $inthat) { if (!is_bool(strpos($inthat, $this)

我面临一个问题。我通过
restapi
发送数据,并使用PHP接受参数值。我在下面解释我的代码

if($action==11){
   $query=$_SERVER['QUERY_STRING'];
   $result=between('searchKey=', '&', $query);
   echo $result;
}
function after ($this, $inthat)
    {
        if (!is_bool(strpos($inthat, $this)))
        return substr($inthat, strpos($inthat,$this)+strlen($this));
    };
function before ($this, $inthat)
    {
        return substr($inthat, 0, strpos($inthat, $this));
    };
function between ($this, $that, $inthat)
    {
        return before ($that, after($this, $inthat));
    };
这里我发送的数据如下

http://example.com/spesh/mobileapi/categoryproduct.php?action=11&searchKey=12%

这里我的问题是,我得到的输出是
12%25
echo$result
,我只需要得到
12%
。而
%
来了,它增加了一些额外的东西。请帮助我解决此问题。

PHP将传入的URL参数自动解码到

如果这不是一个选项(假设URL存储在某个地方),您可以自己用名称不正确的字符串解析查询字符串

最后,从您可以使用的URL中提取查询字符串

这是一个完整的例子,包括所有的部分:

$url = 'http://example.com/spesh/mobileapi/categoryproduct.php?action=11&searchKey=12%25';
$query_string = parse_url($url, PHP_URL_QUERY);
parse_str($query_string, $get);
var_dump($query_string, $get);
给某些字符赋予某些含义,并且
%
已被选为转义字符,这是毫无价值的:

百分比编码机制用于表示数据中的八位字节 当八位字节的对应字符位于 允许的集合或正在用作 组成部分。百分比编码的八位字节编码为字符 三元组,由百分比字符“%”后跟两个 表示该八位字节数值的十六进制数字


这意味着单个文本
%
需要编码为
%25
(仍然只表示
%
)。如果你不遵守自己的规则:你不能使用标准的库和函数,你可能会混淆第三方。例如,任何你键入URL的浏览器都会很乐意为你编码,可能会毁掉它。

你知道你可以使用
echo$_GET['searchKey'而不是?这将为您执行url解码“它添加了一些额外的东西”-这称为url编码…好的,但我使用的是一些不同的功能。有没有这样做的选择?试试这个
string(25) "action=11&searchKey=12%25"
array(2) {
  ["action"]=>
  string(2) "11"
  ["searchKey"]=>
  string(3) "12%"
}