Last active
May 25, 2017 09:27
-
-
Save tps2015gh/695929aee5981aa9f27295a8fda4a6a2 to your computer and use it in GitHub Desktop.
demo_php_regular_expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//====================================================================== | |
// Author: Thitipong Samranvanich | |
// Since : 2017-05-25 | |
// UseFor: Parse PHP CodeIgniter log , Display only Error Rows | |
// Copyright 2016 | |
//====================================================================== | |
// create and test pattern online by https://regex101.com/ | |
$a_str = file("logslog-2017-03-09.php"); | |
$str = join("\r\n",$a_str); | |
$a_match = [] ; | |
$pattern = '/(ERROR - 2017-.+ -->)(.+)/'; | |
foreach($a_str as $idx => $str){ | |
preg_match($pattern,$str,$a_match); | |
if( count($a_match ) > 0 ){ | |
echo "\r\n$idx "; | |
//print_r($a_match); | |
echo $a_match[2]; | |
} | |
} | |
//================================================ | |
$a_str = file("logslog-2017-03-09.php"); | |
$str = join("\r\n",$a_str); | |
$a_match = [] ; | |
$pattern = '/(ERROR - 2017-.+ --> \$config)(\[.+\])(.+)/'; | |
$a_brief = []; | |
foreach($a_str as $idx => $str){ | |
preg_match($pattern,$str,$a_match); | |
if( count($a_match ) > 0 ){ | |
echo "\r\n$idx "; | |
//print_r($a_match); | |
echo $a_match[3]; | |
if(!in_array($a_match[2],$a_brief)){ $a_brief[] = $a_match[2];} | |
} | |
} | |
print_r($a_brief); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment