如何为filter_input添加选项和标志? PHP文档说使用关联数组但没有提供正确语法的任何示例。我尝试了各种格式,包括以下内容:
$textOpts = filter_input(INPUT_POST, "text", FILTER_SANITIZE_STRING, array("options" => FILTER_FORCE_ARRAY, "flags" => !FILTER_FLAG_ENCODE_LOW));
$textOpts = filter_input(INPUT_POST, "text", FILTER_SANITIZE_STRING, array("options" => array(FILTER_FORCE_ARRAY), "flags" => array(!FILTER_FLAG_ENCODE_LOW)));
我似乎无法理解语法,我该怎么写呢?
答案 0 :(得分:3)
<form name="test" id="test" action="" method="POST">
<input type="text" name="demo[]" id="demo[]" value="">
<input type="submit" name="submit-bt" id="submit-bt" value="Submit">
</form>
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$args = array('flags' => FILTER_REQUIRE_ARRAY,
'options' => array('min_range' => 1, 'max_range' => 10)
);
if (!empty($_POST['submit-bt'])){
$textOpts = filter_input(INPUT_POST, "demo", FILTER_VALIDATE_INT, $args);
print_R($textOpts);exit;
}
?>