让PHP停止替换“." $ _GET或$ _POST数组中的字符? [英] Get PHP to stop replacing '.' characters in $_GET or $_POST arrays?

查看:103
本文介绍了让PHP停止替换“." $ _GET或$ _POST数组中的字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我通过$ _GET传递名称中带有.的PHP变量,PHP会自动将其替换为_字符.例如:

If I pass PHP variables with . in their names via $_GET PHP auto-replaces them with _ characters. For example:

<?php
echo "url is ".$_SERVER['REQUEST_URI']."<p>";
echo "x.y is ".$_GET['x.y'].".<p>";
echo "x_y is ".$_GET['x_y'].".<p>";

...输出以下内容:

... outputs the following:

url is /SpShipTool/php/testGetUrl.php?x.y=a.b
x.y is .
x_y is a.b.

...我的问题是:有什么任何方式可以阻止我这样做?无法为我的一生弄清楚我为应得的成就做了什么

... my question is this: is there any way I can get this to stop? Cannot for the life of me figure out what I've done to deserve this

我运行的PHP版本是5.2.4-2ubuntu5.3.

PHP version I'm running with is 5.2.4-2ubuntu5.3.

推荐答案

以下是PHP.net对其解释的解释:

Here's PHP.net's explanation of why it does it:

传入变量名中的点

通常,PHP不会更改 变量名 传递到脚本中.但是, 应该注意的是,句点(句号, 句号)在中不是有效字符 一个PHP变量名.由于这个原因, 看一下:

Dots in incoming variable names

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.

来自 http://ca.php.net/variables.external .

此外,根据此评论,其他字符将转换为下划线:

Also, according to this comment these other characters are converted to underscores:

PHP转换为_(下划线)的字段名称字符的完整列表如下(不仅仅是点):

The full list of field-name characters that PHP converts to _ (underscore) is the following (not just dot):

  • chr(32)()(空格)
  • chr(46)(.)(点)
  • chr(91)([)(方括号)
  • chr(128)-chr(159)(多种)
  • chr(32) ( ) (space)
  • chr(46) (.) (dot)
  • chr(91) ([) (open square bracket)
  • chr(128) - chr(159) (various)

因此,看起来好像您坚持使用它,因此您必须使用

So it looks like you're stuck with it, so you'll have to convert the underscores back to dots in your script using dawnerd's suggestion (I'd just use str_replace though.)

这篇关于让PHP停止替换“." $ _GET或$ _POST数组中的字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆