<?php ini_set('memory_limit', '512M'); $content = file('D:\xampp\htdocs\test\mail.log'); $newArr = array(); $mon = date('M') . ' ' . date('d',strtotime("-1 day")); foreach ($content as $key => $val) { $nk = substr($val,0,6); if (strpos($mon,$nk) === false) { continue; } $pattern = '/((?:(?:25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d?\d))/'; preg_match_all($pattern,$val,$result); $res = $result[0][0]; if (!$res) { continue; } if (!is_array($newArr[$nk])) { $newArr[$nk] = array(); } if (array_key_exists($res, $newArr[$nk])) { $newArr[$nk][$res]++; } else { $newArr[$nk][$res]=1; } unset($content[$key]); } $fp = fopen(date('Y-m-d')."mail.log","a+"); foreach ($newArr as $da=>$value) { $str= $da."\r\n"; foreach($value as $k=>$v) { $str .= "IP:".$k .'--------------'.$v."次\r\n"; } fwrite($fp,$str); } fclose($fp); ?>