php-如何向filter_input添加选项和标志

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php-如何向filter_input添加选项和标志脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

如何在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)));

我似乎无法掌握语法,该怎么写?

解决方法:

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

?>

脚本宝典总结

以上是脚本宝典为你收集整理的php-如何向filter_input添加选项和标志全部内容,希望文章能够帮你解决php-如何向filter_input添加选项和标志所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: