Created
October 17, 2016 02:24
-
-
Save duwaljyoti/a8f194dbb37f80dc55a02a9eb112d5ef to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>PhpFiddle Initial Code</title> | |
<script type="text/javascript"> | |
</script> | |
<style type="text/css"> | |
</style> | |
</head> | |
<body> | |
<?php | |
$file = fopen('example.log', 'r'); | |
$logSummary = []; | |
$dateInArray = false; | |
if($file){ | |
while(!feof($file)){ | |
$line = fgets($file); | |
$wordList = explode(" ", $line); | |
$index = $wordList[0]; | |
foreach ($logSummary as $key => $value) { | |
if($key == $index){ | |
if(preg_match('/error/',array_pop($wordList))){ | |
$value->error += 1; | |
}else { | |
$value->warning += 1; | |
} | |
$dateInArray = true; | |
} | |
} | |
if(!$dateInArray){ | |
$object = getObject(); | |
$type = array_pop($wordList); | |
if(preg_match('/error/',$type)){ | |
$object->error = 1; | |
}else if(preg_match('/warning/',$type)){ | |
$object->warning = 1; | |
} | |
$logSummary[$index] = $object; | |
} | |
$dateInArray = false; | |
} | |
foreach ($logSummary as $key => $value) { | |
echo $key ." warning: " .$value->warning ." error: ". $value->error."<br>"; | |
} | |
} | |
fclose($file); | |
function getObject(){ | |
return (object) [ | |
'warning' => 0, | |
'error' => 0, | |
]; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment