2013-06-23 04:33:51 w3svc1539885 198.56.185.162 get/robots.txt-80-66.249.75.65 mozilla/5.0+ (compatible;+googlebot/ 2.1;++http://www.google.com/bot.html) 404 0 2
I would like to match the date 2013-06-23/time 04:33:51/server ip198.56.185.162/file address robots.txt/spider ip66.249.75.65/Spider information mozilla/5.0+ (compatible; +googlebot/2.1;++http://www.google.com/bot.html)/Status code 404 0 2/, how exactly does this match?
Reply to discussion (solution)
It's best to give a specific example, and then show the results you expect, and your question indicates that you don't understand
It's best to give a specific example, and then show the results you expect, and your question indicates that you don't understand
The code is a specific example, I want to take the value of the following, just want to write a sentence regular match, with Pregmatch this generation of an array and then I do something else.
I think the format of this date should be fixed, you can split them by a space, for example
$log = ' 2013-06-23 04:33:51 w3svc1539885 198.56.185.162 get/robots.txt-80-66.249.75.65 mozilla/5.0+ (COMPATIBLE;+GOOGL ebot/2.1;++http://www.google.com/bot.html) 404 0 2 '; Var_dump (Explode (", $log)); /**array { [0]=> string (Ten) "2013-06-23" [1]=> string (8) "04:33:51" [2]=> String ("w3svc1539885" [3]=> string " 198.56.185.162" [4]=> string (3) "GET" [5]= > string (one) "/robots.txt" [6]=> string (1) "-" [7]=> string (2) " [8]= > string (1) "-" [9]=> string (66.249.75.65) " [10]=> string" mozilla/5.0+ (compatible;+googlebot/2.1;++http://www.google.com/bot.html) " [11]=> string (3)" 404 " [12]= > string (1) "0" [13]=> string (1) "2"}*/
I think the format of this date should be fixed, you can split them by a space, for example
$log = ' 2013-06-23 04:33:51 w3svc1539885 198.56.185.162 get/robots.txt-80-66.249.75.65 mozilla/5.0+ (COMPATIBLE;+GOOGL ebot/2.1;++http://www.google.com/bot.html) 404 0 2 '; Var_dump (Explode (", $log)); /**array { [0]=> string (Ten) "2013-06-23" [1]=> string (8) "04:33:51" [2]=> String ("w3svc1539885" [3]=> string " 198.56.185.162" [4]=> string (3) "GET" [5]= > string (one) "/robots.txt" [6]=> string (1) "-" [7]=> string (2) " [8]= > string (1) "-" [9]=> string (66.249.75.65) " [10]=> string" mozilla/5.0+ (compatible;+googlebot/2.1;++http://www.google.com/bot.html) " [11]=> string (3)" 404 " [12]= > string (1) "0" [13]=> string (1) "2"}*/
I think the format of this date should be fixed, you can split them by a space, for example
$log = ' 2013-06-23 04:33:51 w3svc1539885 198.56.185.162 get/robots.txt-80-66.249.75.65 mozilla/5.0+ (COMPATIBLE;+GOOGL ebot/2.1;++http://www.google.com/bot.html) 404 0 2 '; Var_dump (Explode (", $log)); /**array { [0]=> string (Ten) "2013-06-23" [1]=> string (8) "04:33:51" [2]=> String ("w3svc1539885" [3]=> string " 198.56.185.162" [4]=> string (3) "GET" [5]= > string (one) "/robots.txt" [6]=> string (1) "-" [7]=> string (2) " [8]= > string (1) "-" [9]=> string (66.249.75.65) " [10]=> string" mozilla/5.0+ (compatible;+googlebot/2.1;++http://www.google.com/bot.html) " [11]=> string (3)" 404 " [12]= > string (1) "0" [13]=> string (1) "2"}*/
But the server log is not every line is like this, there are many # beginning, so just want to do a regular filter out the other format.
This point can't be wasted.
Log files are generally very large
You need to read through the loop in a row, split into arrays