[英]php URL decode get '+' from URL
So I am trying to encode/decode a url that when decoded will return the encoded +
symbols from teh url. 所以我试图编码/解码一个url,当解码时将返回来自teh url的编码+
符号。 For example, I encode website.com/index.php?eq=1+12
which when encoded turns the +
into %2B
, as it should. 例如,我对website.com/index.php?eq=1+12
进行了编码,编码website.com/index.php?eq=1+12
+
转换为%2B
,就像它应该的那样。 When I retrieve the value from $_REQUEST['eq']
and use urldecode()
it echo's as "1 12"
. 当我从$_REQUEST['eq']
检索值并使用urldecode()
它回显为"1 12"
。 I cannot seem to get the decode to bring back the +
so to speak. 我似乎无法通过解码来恢复+
这么说。 Am I doing something wrong here, or is there a more efficient/better way to go about doing this? 我在这里做错了什么,或者是否有更有效/更好的方法来做这件事? Here is the exact encode/decode lines I use. 这是我使用的确切编码/解码行。
Submit Page 提交页面
<?php
$eq = "1+12";
$send = '<a href="website.com/index.php?eq='.urlencode($eq).'</a>';
echo $send;
Retrieval page 检索页面
<?php
$eq = urldecode($_REQUEST['eq']);
echo $eq;
?>
Don't run urldecode
, the data in $_REQUEST
is automatically decoded for you. 不要运行urldecode
, $_REQUEST
的数据会自动为您解码。
A plus sign, in a URL, is an encoded space. URL中的加号是编码空间。 PHP decodes the hex value to a +
automatically. PHP自动将十六进制值解码为+
。 Then, by running the result through urldecode
, you are manually (and incorrectly) decoding the +
to a 然后,通过urldecode
运行结果,您手动(并且错误地)将+
解码为a . 。
尝试使用函数rawurldecode()
而不是urldecode()
我使用encodeURIComponent()
在JavaScript中对其进行编码,并使用rawurldecode()
在PHP中对其进行解码,并为我正确编码/解码,包括“+”,但不包含urldecode()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.