Stripping out code from the Drupal watchdog log

This code was written to parse the watchdog log file and pull out lines pertaining to sending notifications. Written on 11/15/2017.
<?php
 
$handle = fopen( 'log.txt', 'r' );
 
$data = '';
 
$nots = array();
 
while ( ( $line = fgets( $handle ) ) !== false ) {
	if( strpos( $line, '|sog_notifications|' ) !== false && 
		strpos( $line, '[regex]' ) === false && 
		strpos( $line, 'uncsog: https://www.sog.unc.edu' ) !== false &&
		strpos( $line, 'feeds tamper' ) === false ) {
 
		$data = substr( $line, strpos( $line, 'Array (' ) + 12 );
		$data = substr( $data, 0, strpos( $data, ' )  ' ) );
 
		$comp = explode( '     ', $data );
 
//		echo '<pre>'; print_r( $comp ); echo '</pre>';
 
		$temp = array();
 
		$temp[ 'name' ] = trim( substr( $comp[ 1 ], 11 ) );
		$temp[ 'value' ] = trim( substr( $comp[ 4 ], 11 ) );
		$temp[ 'target' ] = trim( substr( $comp[ 5 ], 12 ) ); 
 
// echo '<pre>'; print_r( $temp ); echo '</pre>';
 
		$nots[] = $temp;
	}
}
 
fclose( $handle );
 
$count = array( array( 'Number of notifications sent', 'Sent To', 'Name of course', 'Course NID' ) );
 
 
 
for( $i = 0; $i < count( $nots ); $i++ ) {
	$find = in_array_r( $nots[ $i ][ 'value' ], $nots[ $i ][ 'target' ], $count );
 
	if( $find >= 0 ) {
		$count[ $find ][ 'count' ] += 1;
	} else {
		$temp = array();
 
		$temp[ 'count' ] = 1;
		$temp[ 'value' ] = $nots[ $i ][ 'value' ];
		$temp[ 'name' ] = $nots[ $i ][ 'name' ];
		$temp[ 'target' ] = $nots[ $i ][ 'target' ];
 
		$count[] = $temp;
	}
}
 
 
echo '<pre>'; print_r( $count ); echo '</pre>';
 
//echo '<pre>' . print_r( $nots ) . '</pre>';
 
$fp = fopen('notification-spam.csv', 'w');
 
foreach ($count as $fields) {
	fputcsv($fp, $fields);
}
 
fclose($fp);
 
function in_array_r( $value, $target, $haystack ) {
	for( $i = 0; $i < count( $haystack ); $i++ ) {
		if( in_array( $value, $haystack[ $i ] ) && in_array( $target, $haystack[ $i ] ) ) {
			return $i;
		}
	}
 
	return -1;
}