$s = '192.168.0.105 - - [26 p/2007:10:31:15 +0800] "GET /url?a=A&u=http%3A//cn.yahoo.com/&t=\xd1\xc5\xbb\xa2&c=admin&rd=0.811
2959494209535 HTTP/1.1" 404 280 "http://localhost:8008/index.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows';preg_match("/([\d.]+)\s.*?\[(\d+)\s(.*?)\].*?\?a=(\w+)\&u=(.*?)\&t=(.*?)\&c=(.*?)\&.*?\"[\s\d]+\"http:\/\/([^\"]*?)\/.*?\".*/
",$s,$m);
array_shift($m);
print_r($m);

解决方案 »

  1.   


    $s = '192.168.0.105 - - [26 p/2007:10:31:15 +0800] "GET /url?a=A&u=http%3A//cn.yahoo.com/&t=\xd1\xc5\xbb\xa2&c=admin&rd=0.811
    2959494209535 HTTP/1.1" 404 280 "http://localhost:8008/index.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows';preg_match("/([\d.]+)\s.*?\[(\d+)\s(.*?)\].*?\?a=(\w+)\&u=(.*?)\&t=(.*?)\&c=(.*?)\&.*?\"[\s\d]+\"http:\/\/([^\"]*?)\/.*?\".*/
    ",$s,$m);
    array_shift($m);
    print_r($m);
      

  2.   


    $str ='192.168.0.105 - - [26 p/2007:10:31:15 +0800] "GET /url?a=A&u=http%3A//cn.yahoo.com/&t=\xd1\xc5\xbb\xa2&c=admin&rd=0.8112959494209535 HTTP/1.1" 404 280 "http://localhost:8008/index.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; TencentTraveler ; SV1; .NET CLR 1.1.4322)"';$ip = '(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3})'; //ip 
    $date = '\[([^\]]+?)\]';  //date
    $query = '".+?\?([^"]+?)"'; //query
    $host = '"http:\/\/([^\/"]+?)(?=\/|")'; //host$arr = array();
    preg_match("/$ip\s.+\s.+\s$date\s$query\s\d+\s\d+\s$host/i", $str, $arr);print $arr[1]."<br>"; //$ip
    print $arr[2]."<br>"; //$date
    print $arr[3]."<br>"; //query
    print $arr[4]."<br>"; //host
    输出结果192.168.0.105
    26 p/2007:10:31:15 +0800
    a=A&u=http%3A//cn.yahoo.com/&t=\xd1\xc5\xbb\xa2&c=admin&rd=0.8112959494209535 HTTP/1.1
    localhost:8008
    剩下的参数列表自己做个循环就可以获取了!