php filters are used to verify and filter data from non-secure sources (such as user input). the filter function is an important part of the php filter. this chapter introduces you to the filter_var() function in the php filter function. there are it has a certain reference value. friends in need can refer to it. i hope it will be helpful to you.
the filter_var() function filters a variable through a specified filter.
returns filtered data if successful, false if failed.
syntax:
filter_var(variable, filter, options)
variable: required. specifies the variables to filter.
filter: optional. specifies the id of the filter to use. (see filtersid list below)
options: specifies an array containing flags/options. check the possible flags and options for each filter.
@header('content-type:text/html;charset=utf-8;'); $email_a='jcifox@gmail.com'; $email_b='@jcifox@gmail.com'; $email_c='jcifoxgmail.com'; $ip_a='0.0.0.0'; $ip_b='255.255.255.255'; $ip_c='0.0.0.265'; echo $email_a.' : '; echo (filter_var($email_a,FILTER_VALIDATE_EMAIL))?'is valid':'is not valid'; echo '
'; echo $email_b.' : '; echo (filter_var($email_b,FILTER_VALIDATE_EMAIL))?'is valid':'is not valid'; echo '
'; echo $email_c.' : '; echo (filter_var($email_c,FILTER_VALIDATE_EMAIL))?'is valid':'is not valid'; echo '
'; echo $ip_a.' : '; echo (filter_var($ip_a,FILTER_VALIDATE_IP))?'is valid':'is not valid'; echo '
'; echo $ip_b.' : '; echo (filter_var($ip_b,FILTER_VALIDATE_IP))?'is valid':'is not valid'; echo '
'; echo $ip_c.' : '; echo (filter_var($ip_c,FILTER_VALIDATE_IP))?'is valid':'is not valid'; ?>
filtersid name: description
filter_callback: call user-defined function to filter data.
filter_sanitize_string: remove tags, remove or encode special characters.
filter_sanitize_stripped: alias of "string" filter.
filter_sanitize_encoded: url-encode string, remove or encode special characters.
filter_sanitize_special_chars: html escape characters '"& and characters with ascii value less than 32.
filter_sanitize_email: remove all characters except letters, numbers and !#$%&'* - /=?^_`{|}~@.[]
filter_sanitize_url: delete all characters, except letters, numbers and $-_. !*'(),{}|\\^~[ ]`#%";/?:@&=
filter_sanitize_number_int: delete all characters, except numbers and -
filter_sanitize_number_float: delete all characters, except numbers, - and., ee.
filter_sanitize_magic_quotes: apply addslashes().
filter_unsafe_raw: do not perform any filtering, remove or encode special characters.
filter_validate_int: validates values as integers in the specified range.
filter_validate_boolean: if it is "1", "true", "on" and "yes", return true, if it is "0", "false", "off", "no" and " ", returns false. otherwise null is returned.
filter_validate_float: validate the value as a floating point number.
filter_validate_regexp: validate values based on regexp, a perl-compatible regular expression.
filter_validate_url: validate the value as a url.
filter_validate_email: validate the value as e-mail.
filter_validate_ip: validates the value as an ip address.