除了上面提到的\\u剧作家通过链接WordPress Codex, 还有一个非常有用的本机PHP函数,允许您一次性清理来自$\\u POST super global的所有数据:filter_input_array
. 看见php docs. 示例:
// let\'s say I\'m expecting to get data like this:
$_POST = [
\'myString\' => \'Hello World\',
\'myInteger\' => 42,
\'myArrayOfStrings\' => [
\'hello\',
\'world\',
],
];
// sanitizing $_POST super global:
$data = filter_input_array( INPUT_POST, [
\'myString\' => FILTER_SANITIZE_STRING,
\'myInteger\' => FILTER_VALIDATE_INT,
\'myArrayOfStrings\' => [
\'filter\' => FILTER_SANITIZE_STRING,
\'flags\' => FILTER_REQUIRE_ARRAY,
],
] );
// now $data contains array of sanitized values