下边这个样子的日志PHP解析正则咋写?Oct 23 09:46:28 SMS-1 postfix/smtpd[8733]: connect from unknown[192.168.90.6]
Oct 23 09:46:28 SMS-1 postfix/smtpd[8733]: 18FDC3BA695: client=unknown[192.168.90.6], sasl_method=LOGIN, [email protected]
Oct 23 09:46:28 SMS-1 postfix/cleanup[8736]: 18FDC3BA695: message-id=<[email protected]>
Oct 23 09:46:28 SMS-1 postfix/smtpd[8733]: disconnect from unknown[192.168.90.6]
Oct 23 09:46:28 SMS-1 postfix/qmgr[8129]: 18FDC3BA695: from=<[email protected]>, size=10839, nrcpt=1 (queue active)
Oct 23 09:46:28 SMS-1 postfix/smtp[9043]: 18FDC3BA695: to=<[email protected]>, relay=mailcenter.quanshi.com[203.174.100.15]:25, delay=0.12, delays=0.01/0/0.06/0.05, dsn=2.0.0, status=sent (250 2.0.0 q9N1mTgc026815 Message accepted for delivery)
Oct 23 09:46:28 SMS-1 postfix/qmgr[8129]: 18FDC3BA695: removed

解决方案 »

  1.   

    我也写过类似的,VC写好用CStadioFile逐行读取,然后PHP调用
      

  2.   

    <?php
    $file = fopen("zmxc.access_20120516.log","r");
    set_time_limit(0);
    $link = mysql_connect(*) or die('222');//自己的数据库信息
    mysql_select_db('test',$link) or die('111');
    mysql_query ('set names utf8');
    $i =0;
    while($count = fgets($file)){
     $array = explode(' HTTP/1.1 ',$count);
     $string = $array[0];
     $que=substr($array[1],0,3);
     if($que == '200'){
      $i++ ;
        $arr = explode(' +0800] ',$string);
      $ips = explode(' - - [',$arr[0]);
      $t2 =substr(strstr($ips[1],':'),1);
      $t1 = explode(':',$ips[1]);
      $times = $t1[0].' '.$t2;
      $time=strtotime(strtr($times,'/',' '));
         $ip = $ips[0];
      $src = $arr[1];
      if(strstr($src,'&id=')){
       $ids = explode('&id=',$src);
       $id =$ids[1];
      }
      mysql_query("INSERT INTO `logs_16` (`t_id`,`src`,`ip`,`intip`,`time`) VALUES ('$id','$src','$ip', inet_aton('$ip'),'$time')");
       unset($id);
       
     }
    }
    echo $i;
    fclose($fp);       
    ?>