How to add an option and a flag to filter_input

此生再无相见时 提交于 2019-12-10 19:07:13

问题


How do you add both an option and a flag to filter_input? The PHP documentation says to use an associative array but doesn't give any examples on the correct syntax. I've tried various formats, including the following:

$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)));

I can't seem to get the syntax down, how do I write this?


回答1:


<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;
}

?>


来源:https://stackoverflow.com/questions/20077404/how-to-add-an-option-and-a-flag-to-filter-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!