filterconfig PHP filter_var function Filter function

WBOY
Release: 2016-07-29 08:48:27
Original
1198 people have browsed it

The filter_var() function filters variables 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 list of FiltersIDs below)
options: Specifies an array containing flags/options. Check the possible flags and options for each filter.

Copy the code The code is as follows:


@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 the data.
FILTER_SANITIZE_STRING: Remove tags, remove or encode special characters.
FILTER_SANITIZE_STRIPPED: Alias ​​for "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: Remove all characters except numbers and +-
FILTER_SANITIZE_NUMBER_FLOAT: Remove all characters except numbers, +- and.,eE.
FILTER_SANITIZE_MAGIC_QUOTES: Apply addslashes().
FILTER_UNSAFE_RAW: Do not do any filtering, remove or encode special characters.
FILTER_VALIDATE_INT: Validate values ​​as integers in the specified range.
FILTER_VALIDATE_BOOLEAN: Returns true if it is "1", "true", "on" and "yes", and returns false if it is "0", "false", "off", "no" and "". Otherwise NULL is returned.
FILTER_VALIDATE_FLOAT: Validate value as 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 value as e-mail.
FILTER_VALIDATE_IP: Validate the value as an IP address.

The above introduces the filterconfig PHP filter_var function Filter function, including the content of filterconfig. I hope it will be helpful to friends who are interested in PHP tutorials.

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 Tutorials
More>
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!