PHP Regular parsing | extraction | Filtering standard syslog log file contents
Log content:
Dec 15:10:48 root my:192.168.1.51 Test exit Mail Management system
Dec 15:11:23 root my:192.168.1.51 Stella exit Mail management system
...
Extract useful information by regular row by line and return the array
...
After parsing:
Array
[0]=>array (
[0]=>dec 30 15:10:48,
[1]=>root,
[2]=>my,
[3]=>192.168.1.51,
[4]=>test,
[5]=> Exit Mail Management system
),
[1]=>array (
[0]=>dec 30 15:11:23,
[1]=>root,
[2]=>my,
[3]=>192.168.1.51,
[4]=>stella,
[5]=> Exit Mail Management system
),
);
Request, the parsing process
Share to: more
------Solution--------------------
Parsing log files should not use regular expressions (inefficient)
$FN = ' Sys.log ';
$fp = fopen ($FN, ' R ');
while (! feof ($fp)) {
$r [] = fscanf ($fp, "%s%s%s%s my:%s%s%s\n");
}
Print_r ($R);
Array
(
[0] = = Array
(
[0] = Dec
[1] = 30
[2] = 15:10:48
[3] = root
[4] = 192.168.1.51
[5] = = Test
[6] = + Exit Mail Management system
)
[1] = = Array
(
[0] = Dec
[1] = 30
[2] = 15:11:23
[3] = root
[4] = 192.168.1.51
[5] = Stella
[6] = + Exit Mail Management system
)
)