filter_var中按运算符链接的 PHP 常量列表


list of php constants linked by operator in filter_var

我创建了一个名为Sanitize的类。

我使用 filter_var 函数来过滤和清理数据。我从数组构建了 filter_var() 第三个参数:$options类似于以下代码:

private $options = array('typeOfData' => array('options' => array(), 'flags' => array()));

我可以使用正确的选项构建一个数组,但这种方法不起作用。我只想要任何一个选项或标志中的一个,这不会有问题。不幸的是,我想将几个选项或标志常量传递给filter_var。

对于标志,是否可以构建像 FLAG1 |旗帜2?如果不是,我应该使用 filter_var,并根据所需的标志使用filter_var开关吗?

这是使用 filter_var: filter_var($value, $this->filters[$typeOFData], $this->currentOptions); 的当前代码

基于类型进行清理的类:

class Sanitize{
private $data;
private $filteredData;
private $options;
private $typeof;
private $filters;
function __contruct($data){
$this->typeof = gettype($data);
$this->data = $data;
switch ($this->typeof){
    case "integer":
       $this->options = array( /* array of options for integer type*/ );
       $this->filters = array( /*array of all filters you want to use on integers*/ )
        break;
    case "string":
       //....
}
private function getSanitized(){
$filtersNum = count($this->filters);
for($x=0;$x<$filtersNum;$x++){
if(allowsOptions($this->filters[$x])){ $options = $this->options; }else{$options = null;}
$this->filteredData = filter_var($this->data, $this->filters[$x], $options)
}
}
private function allowsOptions($filter){
/* all your code to check*/
return true or false
}
}

我希望这有帮助,如果没有,请告诉我。