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)
http://www.bkjia.com/PHPjc/621664.htmlwww.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...