gongzhonghao.png
扫码关注我们
最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

php使用preg_match()函数验证ip地址的示例代码

来源:http://erdangjiade.com/topic/1739.html 你好,世界。 2017-09-25 22:42浏览(10)

preg_match() 函数用于进行正则表达式匹配,成功返回 1 ,否则返回 0 。这篇文章主要介绍了php使用preg_match()函数验证ip地址的方法,涉及php针对数字及字符串的正则匹配操作相关技巧,需要的朋友可以参考下,具体如下:

<?php
/*
*@return Boolen
*@param String $ip 要匹配的ip地址
*@param String $pat 匹配的正则规则
*@param Boolen 匹配成功后返回的布尔值
*preg_match()
*0为不成功,1为成功
*/
function fun($ip){
    //0.0.0.0--- 255.255.255.255
    $pat = "/^(((1?d{1,2})|(2[0-4]d)|(25[0-5])).){3}((1?d{1,2})|(2[0-4]d)|(25[0-5]))$/";
    if(preg_match($pat,$ip)){
      $num = preg_match($pat,$ip);
      return $num;
    }else{
      $num = preg_match($pat,$ip);
      return $num;
    }
}
echo fun("255.255.255.255");

以上就是php使用preg_match()函数验证ip地址的示例代码的详细内容,更多请关注二当家的素材网其它相关文章!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2