Home > Backend Development > PHP Tutorial > Filter function in php to verify and filter user-entered data_PHP tutorial

Filter function in php to verify and filter user-entered data_PHP tutorial

WBOY
Release: 2016-07-13 10:41:23
Original
905 people have browsed it

Introduction to PHP Filter

PHP filters are used to validate and filter data from non-secure sources (such as user input).

Copy code The code is as follows:

//Remove html tags, or remove encoded special characters
var_dump(filter_var( "中文ABC@#<script>abc</script>BBB",FILTER_SANITIZE_STRING));

// url_encoded encoding, remove or encode special characters
var_dump(filter_var("http://中文",FILTER_SANITIZE_ENCODED));

//html escape characters ""<>& and ASCII value Less than 32 characters.
var_dump(filter_var("",FILTER_SANITIZE_SPECIAL_CHARS));

//Delete all characters except letters, numbers and !#$%&'*+-/=? ^_`{|}~@.[]
var_dump(filter_var("AS$&><",FILTER_SANITIZE_EMAIL));

//Delete all characters except letters, numbers and $- _.+!*'(),{}|\^~[]`<>#%";/?:@&=
var_dump(filter_var("k<>!",FILTER_SANITIZE_URL)) ;

//Delete all characters, except numbers and +-
var_dump(filter_var("123ABC++",FILTER_SANITIZE_NUMBER_INT));

//Delete all characters, except numbers, + - and.,eE.
var_dump(filter_var("mm.,pp",FILTER_SANITIZE_NUMBER_FLOAT));

//Apply addslashes
var_dump(filter_var("aa//''",FILTER_SANITIZE_MAGIC_QUOTES));

//Verify the value as an integer in the specified range
var_dump(filter_var(20,FILTER_VALIDATE_INT,array("options"=>array("min_range"=>10,"max_range"=>51) )));

//If it is "1", "true", "on" and "yes", return true, if it is "0", "false", "off", "no " and "", returns false. Otherwise NULL is returned.
var_dump(filter_var(1,FILTER_VALIDATE_BOOLEAN));

//Verify the value as a floating point number.
var_dump(filter_var(222,FILTER_VALIDATE_FLOAT));

//Verification URL
var_dump(filter_var("http://www.baidu.com",FILTER_VALIDATE_URL));

//Verify email
var_dump(filter_var("abcd@123.com",FILTER_VALIDATE_EMAIL));

//Verify IP address
var_dump(filter_var("1.1.1.266",FILTER_VALIDATE_IP ));

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/695099.htmlTechArticlePHP Filter Introduction PHP filters are used to validate and filter data from non-secure sources (such as user input). Copy the code. The code is as follows: //Remove html tags, or remove encoding special...
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