日期:2014-05-17 浏览次数:20498 次
?
?
This extension filters data by either validating or sanitizing it. This is especially useful when the data source contains unknown (or foreign) data, like user supplied input. For example, this data may come from an HTML form.
There are two main types of filtering: validation and sanitization.
Validation
is used to validate or check if the data meets certain qualifications. For
example, passing in FILTER_VALIDATE_EMAIL
will
determine if the data is a valid email address, but will not change the data
itself.
Sanitization
will sanitize the data, so it may alter it by removing undesired characters. For
example, passing in FILTER_SANITIZE_EMAIL
will
remove characters that are inappropriate for an email address to contain. That
said, it does not validate the data.
Flags are optionally used with both
validation and sanitization to tweak behaviour according to need. For example,
passing in FILTER_FLAG_PATH_REQUIRED
while
filtering an URL will
require a path (like /foo in http://example.org/foo) to be
present.
?
这个扩展过滤器数据通过验证和消毒。这是特别有用,当数据源包含未知(或外国)数据,比如用户提供的输入。例如,这个数据可能来自一个HTML表单。 有两种主要类型的过滤:验证和数据消毒。 验证是用于验证或检查数据满足一定的条件。例如,通过在滤波器验证电子邮件将决定如果数据是一个有效的电子邮件地址,但不会改变数据本身。 将清洁卫生处理的数据,所以它可能改变它通过消除不受欢迎的人物。例如,通过在过滤净化电子邮件将删除字符不含有一个电子邮件地址。据说,它不验证数据。 旗帜是选择性地用于验证和数据消毒根据需要来调整行为。例如,passin
?
过滤的函数列表:
函数名 功能
filter_list 过滤器列表——返回一个列表的所有支持的过滤器
filter_id 过滤器ID -返回过滤器ID属于一个名叫过滤器
filter_has_var 过滤器已经var -检查如果变量指定类型的存在
filter_input 过滤输入——得到一个特定的外部变量的名称,并选择性地过滤它
filter_input_array 过滤输入数组——得到外部变量和选择性地过滤它们
filter_var 使用filter_var过滤变量指定的过滤器
filter_var_array 过滤器var数组——得到多个变量和选择性地过滤它们
?
?
?
?
函数示例:
filter_list
?
<?php print_r(filter_list()); ?> 以上例程的输出类似于: Array ( [0] => int [1] => boolean [2] => float [3] => validate_regexp [4] => validate_url [5] => validate_email [6] => validate_ip [7] => string [8] => stripped [9] => encoded [10] => special_chars [11] => unsafe_raw [12] => email [13] => url [14] => number_int [15] => number_float [16] => magic_quotes [17] => callback )
?
?filter_list和filter_id结合
?
<?php echo "<pre>"; print_r(filter_list()); echo "</pre>"; foreach (filter_list() as $key => $value) { echo "<br>".$key."=".$value.'='.filter_id($value); } ?> 0=int=257 1=boolean=258 2=float=259 3=validate_regexp=272 4=validate_url=273 5=validate_email=274 6=validate_ip=275 7=string=513 8=stripped=513 9=encoded=514 10=special_chars=515 11=unsafe_raw=516 12=email=517 13=url=518 14=number_int=519 15=number_float=520 16=magic_quotes=521 17=callback=1024
?
?filter_id
?
&l