将 $ 编码为 ASCII
在我的 HTML 文件中,我通过 GET
向 php.ini 提供了一个值。该值如下:'var1$var2'
。
在我的 URL 中,显示以下内容:
/phpmethod.php?q=var1%24var2
我在 ASCII 表中查找了 $
,发现它的数字是 24。
我也尝试将其添加
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
到 html 中,但它是相同的结果。
我该如何解决这个问题?
In my HTML-file, I give a value via GET
to a php. The value is the following: 'var1$var2'
.
In my URL, there is shown the following:
/phpmethod.php?q=var1%24var2
I looked up $
in the ASCII table and found out that it has the number 24.
I also tried it with adding
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
to the html but it´s the same result.
How can I solve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 urldecode 将值转换回发布的值。
通常,您不需要这些 - 您的
$_GET
和$_POST
已经被解码,并且将包含var1$var2
就像用户一样进入了他们。Use urldecode to transform the value back to the posted value.
Usually, you wont need these - your
$_GET
and$_POST
will already be decoded, and will contain thevar1$var2
just like the user entered them.这是正常的——应该是这样。
$
是一个特殊字符,如果包含在 URL 中,则可以具有特殊含义。因此,每当您发送包含$
的值时,该字符都会被转义(urlencoded)为其十六进制值,因此var1$var2
将是 <代码>var1%24var2。当您在目标页面 (phpmethod.php) 中写入
GET['q']
时,$
字符会自动urldecoded,您将获取原始值var1$var2
,这样您就无需担心任何事情。其他也被转义的字符包括空格 (
%20
)、/
、:
、&
、?
等。0x7F
以上的所有 Unicode 字符也将被转义。您应该仅在对数据显式使用
urlencode
的情况下使用urldecode
函数;所以永远不要对$_POST
和$_GET
值进行 urldecode;它们已经被解码,您再次这样做可能会损坏您的数据。This is normal -- what it should be.
$
is a special character and can have special meanings if included in a URL. So whenever you send a value that contains$
this character will be escaped (urlencoded) to its hexadecimal value, sovar1$var2
will bevar1%24var2
.When in your target page (phpmethod.php), you write
GET['q']
the$
character is automatically urldecoded and you'll get the original valuevar1$var2
so you don't need to worry about anything.Other characters that are also escaped include space (
%20
),/
,:
,&
,?
, etc. Also all Unicode characters above0x7F
will be escaped too.You should only use
urldecode
function in a situation when you explicitly usedurlencode
on your data; so never urldecode$_POST
and$_GET
values; their already decoded and you might corrupt your data by doing that again.您是否尝试过仅传递 var1$var2 并在获得该值时转义该值?
我不是 php 编码员,所以如果它有效的话我现在不会,但我想它应该。
Have you tried just passing var1$var2 and escaping the value when you get it?
I'm no php coder so I wouldn't now if that works, but I guess it should.