081902XXX.txt
082002XXX.txt
082102XXX.txt
082202XXX.txt
082302XXX.txt
Im trying to loop once through all these files and output the columns, but my code doesnt seem to loop logically. Anyone know what I could be doing wrong here ?
**** PLEASE USE THE
Code: Select all
TAG WHEN POSTING *****[/color]Code: Select all
<?PHP
//date format example 082102XXX.txt is February 21, 2007 OR Year-Day-Month
//read file name in directory
$today = date("ydm");
$CURRENT_YEAR = substr($today,0,2); //08
$CURRENT_DAY = substr($today,2,2); //21
$CURRENT_MONTH = substr($today,4,2); //02
for ($i=0;$i<5;$i++) {
$filename = $CURRENT_YEAR . $CURRENT_DAY+$i . $CURRENT_MONTH . 'XXX.txt';
//Open asrunlogs directory
$dir = @ opendir("./asrunlogs");
//List files in asrun directory directory
while (($filename = readdir($dir)) !== false && $filename != '.' && $filename != '..') {
echo '<b>Displaying contents of' . $filename . '</b><BR>';
//parse contents in file
$file_handle = file_get_contents('./asrunlogs/' . $filename);
// Explodes .txt file into lines (\n)
$Lines = explode("\n",$file_handle);
//display fields from file
foreach($Lines as $Line) {
$Line = preg_replace('/\s\s+/', ' ', trim($Line));
$fields = explode(" ",$Line);
if ($Line != 'XXX As Run.txt'){
echo $fields[1] . ' ' . $fields[2] . ' ' . $fields[3] . '<BR>';
}
}
}
}
closedir($dir);
?>