I'm having an issues with this PHP code. Its supposed to extract the total amount of errors that occur in a log file. Every time I run it, I get this error: Undefined offset: 2
<?php
$handle = fopen('../../apache2/logs/error.log','r') or die ('File opening failed');
$requestsCount = 0;
$numerror = 0;
while (!feof($handle)) {
$dd = fgets($handle);
$requestsCount++;
$parts = explode('"', $dd);
$statusCode = substr($parts[2], 0, 4);
if (hasRequestType($statusCode, 'error')) $numerror++;
}
echo "Total Errors: " . $numerror . "<br />";
fclose($handle);
function hasRequestType($l,$s) {
return substr_count($l,$s) > 0;
}
?>
Any help would be great