Monday, February 11, 2019

Scan json data in logs file php


CRAWL LOG FILES - V1.0

$dir = "Logs1/";
$re = '/{"Id":0,"TransAmount(.*?)\}/';

$files = scandir($dir);

//DONWLOAD
$handle = fopen("transactionMissing.txt", "w");

foreach ($files as $key => $value) {
if(substr( $value, 0, 1 ) === ".")
continue;

$str = file_get_contents($dir.$value);
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);

foreach ($matches as $key1 => $value1) {
fwrite($handle, $value1[0].',');
printf($value1[0].'
');
}
}

// fclose($handle);

// header('Content-Type: application/octet-stream');
// header('Content-Disposition: attachment; filename='.basename('transactionMissing.txt'));
// header('Expires: 0');
// header('Cache-Control: must-revalidate');
// header('Pragma: public');
// header('Content-Length: ' . filesize('transactionMissing.txt'));
// readfile('transactionMissing.txt');
exit;
?>


No comments:
Write comments