问题描述
我有一个问题,PHP用POST和GET变量中的下划线替换所有空格.
I have the problem, that PHP replaces all spaces with underlines in POST and GET variables.
例如,如果我有URL: http://localhost/proxy.php?user 名称=最大浏览器会将其转换为 http://localhost/proxy.php?user%20name = Max .
For example if I have the URL: http://localhost/proxy.php?user name=Maxthe browser will convert it to http://localhost/proxy.php?user%20name=Max.
但是,如果我给出$ _GET参数,则密钥不是用户名,而是用户名!
But if I give the $_GET parameters out, the key is not user name but user_name!
是否有可能改变这种行为?
Is there any possibility to change this behaviour?
推荐答案
来自 PHP手册:
通常,PHP不会更改 变量名 传递到脚本中.但是, 应该注意的是,句点(句号, 句号)在中不是有效字符 一个PHP变量名.由于这个原因, 看一下:
Typically, PHP does not alter the names of variables when they are passed into a script. However, it should be noted that the dot (period, full stop) is not a valid character in a PHP variable name. For the reason, look at it:
<?php $varname.ext; /* invalid variable name */ ?>
现在,什么 解析器看到的是一个名为 $ varname,后跟字符串 串联运算符,然后是 裸字符串(即,无引号的字符串 与任何已知密钥都不匹配或 保留字)"ext".显然,这 没有预期的结果.
Now, what the parser sees is a variable named $varname, followed by the string concatenation operator, followed by the barestring (i.e. unquoted string which doesn't match any known key or reserved words) 'ext'. Obviously, this doesn't have the intended result.
因此,重要的是 请注意,PHP会自动 替换传入变量中的任何点 带有下划线的名称.
For this reason, it is important to note that PHP will automatically replace any dots in incoming variable names with underscores.
以及页面上的评论:
chr(32) ( ) (space)
chr(46) (.) (dot)
chr(91) ([) (open square bracket)
chr(128) - chr(159) (various)
PHP不可逆地修改包含这些字符的字段名称,以尝试与已弃用的register_globals功能兼容.
PHP irreversibly modifies field names containing these characters in an attempt to maintain compatibility with the deprecated register_globals feature.
这篇关于PHP用下划线替换空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!