【发布时间】:2014-04-23 20:27:52
【问题描述】:
为什么这不起作用?
session_start();
print("<pre>".print_r($_POST['foo'],true)."</pre>"); // 'Bob '
array_walk_recursive($_POST, function (&$val) { $val = trim($val); });
print("<pre>".print_r($_POST['foo'],true)."</pre>"); // 'Bob'
$_SESSION['foo'] = filter_input(INPUT_POST, 'foo', FILTER_SANITIZE_STRING);
print("<pre>".print_r($_SESSION['foo'],true)."</pre>"); // 'Bob '
【问题讨论】:
-
FILTER_SANITIZE_STRING不修剪空白字符:Strip tags, optionally strip or encode special characters.为什么从$_POST切换到INPUT_POST?这种不一致是在自找麻烦。 -
我怀疑
filter_input()的数据不是来自$_POST,而是来自$_POST最初所在的位置。也就是说,更改$_POST的内容不会对filter_input()的行为产生任何影响。 -
@JohnConde 是的,但是我在通过
filter_input()之前已经修剪了 $_POST。
标签: php session post multidimensional-array trim