Phpfilter (1) PHP filters include two types
Validation: used to verify that the verification item is valid
Sanitization: used to format the verified project. Therefore, it may modify the value of the verification item and delete invalid characters.
The input_filters_list () function is used to list all filters supported by the current system.
1
2
Filter Name |
Filter ID |
3 $filter)5 {6 echo '
'.$filter.' |
'.filter_id($filter).' |
'."\n";7 }8 ?>9
The above code will output the following information:
Filter Name Filter ID
Int 257
Boolex 258
Float 259
Validate_regexp 272
Validate_url 273
Validate_email 274
Validate_ip 275.
String 513
Stripped 513
Encoded 514.
Special_chars 515
Unsafe_raw 516
Email 517
Urls 518
Number_int 519
Number_float 520
Magic_quotes 521
Callback 1024
Each filter has a unique ID. Each filter can be used by the filter_var () function. The following describes how to use it one by one. Note that the preceding string and strippedID are the same because they are the same filter or two aliases of the same filter.
Filter data
Use the filter_var () method to filter data. The following is a simple filtering example.
1
The code above will data an integer of 1234, because the $ int variable is verified by the integer type, this time change the content of the $ int variable
1
At this time, the code is running and no variable output is found. this is because the $ in variable is not verified, so this method returns bool (false ). Note that bool (false) is returned even if $ int =)
Integer verification
The above code simply verifies whether the given value is an integer. In fact, FILTER_VALIDATE_INT also provides a value range verification. next we will verify a variable, determine whether it is an integer, and verify whether its value is between 50 and 100.
1
$min, "max_range"=>$max));11 //4212 ?>
Running the code above, I found 42 was output, and no error was found. why? When you want to add a verification rule to the verification, you must pass an array containing the 'options' key as follows:
1
array("min_range"=>$min, "max_range"=>$max)));11 12 ?>
When you run the code above, no output is displayed on the page. if false is returned, the verification is successful. This method can also be used to verify the range of negative numbers. this method also supports single-range values, that is, only specifying a maximum or minimum value range, such
array('min_range'=>$min)));//12?>
The above code verifies whether $ int is an integer value greater than (not including equal to) $ min. run the code and output 12
The above examples are just simple verification of a single value. what if we verify a group of variables? The answer is filter_var_array (). This function can verify multiple data types at the same time. Here is a simple example.
1
$value)11 {12 echo $key.' -- '.$value.'
';13 }14 ?>
Run the above code and output the following code:
0 -- 10
1 -- 109
2 --
3 ---1234
4 --
5 --
6 -- Array
The FILTER_VALIDATE_INT filter supports both octal and hexadecimal. The two flags are:
FILTER_FLAG_ALLOW_HEX
FILTER_FLAG_ALLOW_OCTAL
Pass flags using arrays
1
FILTER_FLAG_ALLOW_HEX));8 //2559 ?>
PHP technology exchange group 170855791