Home php教程 php手册 PHP Filter function--filter_var() function

PHP Filter function--filter_var() function

May 16, 2016 am 09:00 AM
filter_var php

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:
<? 
@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 '<br /><br />'; 
echo $email_b.' : '; 
echo (filter_var($email_b,FILTER_VALIDATE_EMAIL))?'is valid':'is not valid'; 
echo '<br /><br />'; 
echo $email_c.' : '; 
echo (filter_var($email_c,FILTER_VALIDATE_EMAIL))?'is valid':'is not valid'; 
echo '<br /><br />'; 
echo $ip_a.' : '; 
echo (filter_var($ip_a,FILTER_VALIDATE_IP))?'is valid':'is not valid'; 
echo '<br /><br />'; 
echo $ip_b.' : '; 
echo (filter_var($ip_b,FILTER_VALIDATE_IP))?'is valid':'is not valid'; 
echo '<br /><br />'; 
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.

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

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

See all articles