PHP Regular Parsing | extract | Filter the contents of the Syslog Journal file of the standard

Source: Internet
Author: User
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
)

)
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.