문제

Why doesn't this work?

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     '
도움이 되었습니까?

해결책

From the first comment in the manual:

Note that this function doesn't (or at least doesn't seem to) actually filter based on the current values of $_GET etc. Instead, it seems to filter based off the original values.

edit

Here's where you would add your call to trim():

$_SESSION['foo'] = trim(filter_input(INPUT_POST, 'foo', FILTER_SANITIZE_STRING));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top