[英]Pass a percent (%) sign in a url and get exact value of it using php
I am trying to pass percent (%) sign in url like 我试图将百分号(%)传递给url
%B6011000995504101^SB
but when I echo, it returns 但当我回声时,它会回来
♦011000995504101^SB
I want exact same value as I pass it in URL. 我想要在URL中传递完全相同的值。
I have tried to use urlencode() function, but it give me output like this... 我试过使用urlencode()函数,但它给我这样的输出...
%B6011000995504101%5ESB
please help me regarding this 请帮我解决这个问题
To send a %
sign in a url, instead send %25
. 要在网址中发送%
符号,请发送%25
。
In your case, in order for php to see a percent sign, you must pass the character string %25B6011000995504101^SB
to the server. 在您的情况下,为了让php看到百分号,您必须将字符串%25B6011000995504101^SB
传递给服务器。
In URLs, the percent sign has special meaning. 在URL中,百分号具有特殊含义。 Is used to encode special characters. 用于编码特殊字符。 For example, &
is the separator between parameters, so if you want your parameter to actually contain an &
, you instead write %26
. 例如, &
是参数之间的分隔符,因此如果您希望参数实际包含 &
,则改为编写%26
。 Because the percent sign is used to encode special characters, it is also a special character, and so if you want to actually send a percent sign, it must also be encoded. 因为百分号用于编码特殊字符,所以它也是一个特殊字符,因此如果要实际发送百分号,也必须对其进行编码。 The encoding for a percent sign is %25
. 百分号的编码是%25
。
Before including a raw string in a URL it's a good idea to pass it through urlencode like so: 在URL中包含原始字符串之前,最好通过urlencode传递它,如下所示:
<?php
$original='%B6011000995504101^SB';
$updated=urlencode($original);
echo "<a href=\"some_page.php?$updated\">Link here</a>";
?>
The receiving page will know what to do - give this example a try on your webserver: 接收页面将知道该怎么做 - 在您的网络服务器上试试这个例子:
<?php
if($_GET['argument']) {
echo "<p>You passed in the argument "$_GET[argument]"</p>";
}else {
echo "<p>No argument was passed.</p>";
}
$original='%B6011000995504101^SB';
$updated=urlencode($original);
echo "<a href=\"urlencode.php?argument=$updated\">Link here</a>";
?>
(name the file urlencode.php ) (将文件命名为urlencode.php )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.