gpt4 book ai didi

php - 让 PHP 停止替换 $_GET 或 $_POST 数组中的 '.' 个字符?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:50:30 26 4
gpt4 key购买 nike

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

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

...输出以下内容:

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

...我的问题是:是否有任何方法可以停止这种情况?我这辈子都想不通我做了什么才配得上这个

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

最佳答案

这是 PHP.net 对其原因的解释:

Dots in incoming variable names

Typically, PHP does not alter thenames of variables when they arepassed into a script. However, itshould be noted that the dot (period,full stop) is not a valid character ina PHP variable name. For the reason,look at it:

<?php
$varname.ext; /* invalid variable name */
?>

Now, whatthe parser sees is a variable named$varname, followed by the stringconcatenation operator, followed bythe barestring (i.e. unquoted stringwhich doesn't match any known key orreserved words) 'ext'. Obviously, thisdoesn't have the intended result.

For this reason, it is important tonote that PHP will automaticallyreplace any dots in incoming variablenames with underscores.

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

此外,根据 this comment这些其他字符被转换为下划线:

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

  • chr(32) ( ) (space)
  • chr(46) (.) (dot)
  • chr(91) ([) (open square bracket)
  • chr(128) - chr(159) (various)

所以看起来你被困住了,所以你必须使用 dawnerd's suggestion 将脚本中的下划线转换回点。 (不过我只会使用 str_replace。)

关于php - 让 PHP 停止替换 $_GET 或 $_POST 数组中的 '.' 个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14432700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com