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


php manual: filter_var_array()

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

can $definition argument of filter_var_array() call ever work? (array syntax >= php5.4)

   $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]],           ]; 

is using 1 flag @ time way use flags when using filter_input_array()? example: (written out long way, although loop).

   $def1 = [              'firstname' => ['filter' => filter_sanitize_string,                              'flags'  => filter_require_scalar],              'lastname'  => ['filter' => filter_sanitize_string,                              'flags'  => filter_require_scalar]            ];     $def2 = [              'firstname' => ['filter' => filter_sanitize_string,                              'flags'  => filter_flag_no_encode_quotes],              'lastname'  => ['filter' => filter_sanitize_string,                              'flags'  => filter_flag_no_encode_quotes]            ];     $def3 = [              'firstname' => ['filter' => filter_sanitize_string,                              'flags'  => filter_flag_strip_low],              'lastname'  => ['filter' => filter_sanitize_string,                              'flags'  => filter_flag_strip_low]            ];     $def4 = [              'firstname' => ['filter' => filter_sanitize_string,                              'flags'  => filter_flag_strip_high],              'lastname'  => ['filter' => filter_sanitize_string,                              'flags'  => filter_flag_strip_high]            ]; 

just make sure not put flags inside own array. options can in array, flags need seen 1 whole thing separated 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]           ]; 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -