当前位置:首页 > PHP教程 > php函数 > 列表

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

发布:smiling 来源: PHP粉丝网  添加日期:2014-08-17 16:04:47 浏览: 评论:0 
  1. function matchip($q){ 
  2. 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); 
  3. return $matches[0]; 
  4. } 
  5. $ipaddress = '201.103.2.2'; 
  6. $iperror ='262.3.6.6'; 
  7. $iptest = matchip( $ipaddress ); 
  8. //当我们给matchip 的值为$ipaddress输出为201.103.2.2 
  9. //当我们给matchip的函数值为$iperror时,输出值为 62.3.6.6 
  10.  代码如下 复制代码 
  11. if( $iptest ) 
  12. { 
  13.  echo $iptest; 
  14. } 
  15. else 
  16. { 
  17.  echo 'phpfensi.com提示:你输的的ip地址有问题'; 
  18. } 

Tags: php 判断IP 正则表达式

分享到: