PHP 5.4: Can I use multiple flags with a filter using filter_var_array()?

前端 未结 1 1265
忘了有多久
忘了有多久 2020-12-20 20:20

PHP Manual: filter_var_array()

mixed filter_var_array ( array $data [, mixed $definition [, bool $add_empty = true ]] )

Can something like

相关标签:
1条回答
  • 2020-12-20 20:58

    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 the bitwise OR operator (|).

       $def = [
          'firstName' => ['filter' => FILTER_SANITIZE_STRING,
                           'flags' => FILTER_REQUIRE_SCALAR | FILTER_FLAG_NO_ENCODE_QUOTES | FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH],
          'lastName'  => ['filter' => FILTER_SANITIZE_STRING,
                           'flags' => FILTER_REQUIRE_SCALAR | FILTER_FLAG_NO_ENCODE_QUOTES | FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH]
       ];
    
    0 讨论(0)
提交回复
热议问题