一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

php 判断IP是否合法正则表达式代码

时间:2010-07-08 编辑:简简单单 来源:一聚教程网

 代码如下 复制代码

function matchip($q){
preg_match('/((25[0-5])|(2[0-4]d)|(1dd)|([1-9]d)|d)(.((25[0-5])|(2[0-4]d)|(1dd)|([1-9]d)|d)){3}/', $q, $matches);
return $matches[0];
}

$ipaddress = '201.103.2.2';
$iperror ='262.3.6.6';

$iptest = matchip( $ipaddress );
//当我们给matchip 的值为$ipaddress输出为201.103.2.2
//当我们给matchip的函数值为$iperror时,输出值为 62.3.6.6

 代码如下 复制代码
if( $iptest )
{
 echo $iptest;
}
else
{
 echo '111com.net提示:你输的的ip地址有问题';
}

热门栏目