Home> php教程> php手册> body text

PHP Filter function--filter_var() function

WBOY
Release: 2018-09-27 14:17:39
Original
1906 people have browsed it

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)
Copy after login

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.

the code is as follows:

'; 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'; ?>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!