Home > Backend Development > PHP Tutorial > php利用自带filter_var函数验证邮箱、url和ip地址

php利用自带filter_var函数验证邮箱、url和ip地址

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-20 13:04:13
Original
1562 people have browsed it

php程序中验证邮箱,IP地址或url一般大家都会使用正则表达式来处理,其实在php里面有一些内置的专门验证规则。

下面用实例说说如何使用php内置filter_var函数来验证email,ip以及URL。

1、filter_var验证邮箱

<p>$email='scutephp@163.com'; </p>$result=filter_var($email,FILTER_VALIDATE_EMAIL); <br />var_dump($result);
Copy after login

//输出:string(17) 'scutephp@163.com'

2、filter_var验证url地址

<p>$url='http://www.scutephp.com/'; </p>$result=filter_var($url,FILTER_VALIDATE_URL); <br />var_dump($result);
Copy after login

//输出:string(25) 'http://www.scutephp.com/'

3、filter_var验证ip地址

<p>$url='192.168.0.1'; </p>$result=filter_var($url,FILTER_VALIDATE_IP); <br />var_dump($result);
Copy after login

//输出:string(11) '192.168.0.1'

php中的filter函数还可用来验证浮点数,整形数字,布尔类型等等


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
Latest Issues
Get URL parameters in PHP.
From 1970-01-01 08:00:00
0
0
0
How to check if a URL exists via PHP?
From 1970-01-01 08:00:00
0
0
0
PHP api returns json to extract url and jump?
From 1970-01-01 08:00:00
0
0
0
php WeChat payment callback url
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template