PHP:使用filter_var_array应用通用过滤器?
我已经尝试了 filter_var_array()
的各种组合和排列,但尚未找到答案:
给定一个相当大的关联数组,我需要将 FILTER_SANITIZE_STRING
与为数组中的所有元素添加 FILTER_FLAG_STRIP_LOW
标志。
因此:
filter_var_array($my_big_array,FILTER_SANITIZE_STRING);
应用 FILTER_SANITIZE_STRING
过滤器,但不使用 FILTER_FLAG_STRIP_LOW
标志。
并且......
filter_var_array($my_big_array,FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
引发错误。
是否可以使用filter_var_array()
轻松应用通用过滤器?
I've tried various combinations and permutations of filter_var_array()
and have yet to find the answer to this:
Given a rather large associative array, I need to apply FILTER_SANITIZE_STRING
with the FILTER_FLAG_STRIP_LOW
flag to ALL of the elements in the array.
So:
filter_var_array($my_big_array,FILTER_SANITIZE_STRING);
applies the FILTER_SANITIZE_STRING
filter but without the FILTER_FLAG_STRIP_LOW
flag.
And...
filter_var_array($my_big_array,FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
Brings up an error.
Is it possible to easily apply a common filter using filter_var_array()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的filter_var_array () 语法
第二个 filter_var_array() 参数需要是 PHP 手册中正确的 $ 定义。
示例:
只要确保您没有将标志放入它们自己的数组中即可。选项可以位于数组中,但标志需要被视为由管道分隔的一个整体。
Good filter_var_array() syntax
The second filter_var_array() argument needs to be a proper $definition as per the PHP manual.
Example:
Just make sure you do not put the flags inside their own array. Options can be in an array, but the flags need to be seen as one whole thing separated by pipes.
您应该能够通过二元运算符组合它们,如 FILTER_SANITIZE_STRING & 中所示。 FILTER_FLAG_STRIP_LOW,但我还没有测试过。
You should be able to combine them via binary operators, as in
FILTER_SANITIZE_STRING & FILTER_FLAG_STRIP_LOW
, but I haven't tested this yet.