学习PHP函数:preg_match_all

<?php
$str = '10.10.10.10, 10.10.10.11';
 preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $str, $matches);
var_dump($matches);

输出:

array(1) {
  [0]=>
  array(2) {
    [0]=>
    string(11) "10.10.10.10"
    [1]=>
    string(11) "10.10.10.11"
  }
}

感觉好厉害的样子,晚上学习。这个正则可用来处理$_SERVER['HTTP_X_FORWARDED_FOR'],进而拿到clientip

posted on 2013-08-09 15:24  awildfish  阅读(181)  评论(0编辑  收藏  举报

导航