Home > Backend Development > PHP Tutorial > PHP uses filter filter to verify email address ipv6 address url verification_PHP tutorial

PHP uses filter filter to verify email address ipv6 address url verification_PHP tutorial

WBOY
Release: 2016-07-13 17:18:22
Original
1002 people have browsed it

1. Verify email

Copy code The code is as follows:

$email = 'jb51@qq.com';
$result = filter_var ($email, FILTER_VALIDATE_EMAIL);
var_dump($result); //string(14) "jb51@qq.com"

2. Verify url address

Copy code The code is as follows:

$url = "http://www.jb51.net";
$result = filter_var($url, FILTER_VALIDATE_URL);
var_dump($result); //string(22) "http://www.jb51.net"

3. Verify IP address

Copy code The code is as follows:

$url = "192.168.1.110";
$result = filter_var($ url, FILTER_VALIDATE_IP);
var_dump($result); //string(13) "192.168.1.110"

It’s worth mentioning that this method can also be used to verify ipv6.

Copy code The code is as follows:

$url = "2001:DB8:2de::e13";
$ result = filter_var($url, FILTER_VALIDATE_IP);
var_dump($result); //string(17) "2001:DB8:2de::e13"

4. Verify whether the value is an integer and within an integer interval

Copy code The code is as follows:

$i = '010';
$result = filter_var(
$i,
FILTER_VALIDATE_INT,
//Set the value range for verification
array(
'options' => array('min_range' => 1, 'max_range' => 100)
)
);
var_dump($result);//bool(false)

PHP variables are weakly typed. If no filter is used and the greater than or less symbol is used directly to judge, it will be true.

Copy code The code is as follows:

$i = '010';
$result = $i >= 1 && $i <= 100;
var_dump($result);//bool(true)

5. Verify floating point numbers

Copy code The code is as follows:

$float = 12.312;
$result = filter_var($float, FILTER_VALIDATE_FLOAT) ;
var_dump($result); //float(12.312)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621664.htmlTechArticle1. The verification email copy code is as follows: $email = 'jb51@qq.com'; $result = filter_var ($email, FILTER_VALIDATE_EMAIL); var_dump($result); //string(14) "jb51@qq.com" 2. Verify url...
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