My main index includes() a php file that generates some tables that contain information about recent site updates. The news updates are stored in individual text files in a "news" folder. The news update files are loaded into HTML tables and the 6 latest update are shown. I did this to make site updates easier for a friend who is also working on the site. However, I'm having problems getting it to work correctly. Here's my code:
<?
$handle=opendir("news");
//Loads all the files in the directory
while ($file = readdir($handle))
{
if (($file!=".") && ($file!=".."))
{
$retVal[count($retVal)] = $file;
}
}
//Clean up and sort
closedir($handle);
sort($retVal);
//Reverse it back for my convenience
$retVal=array_reverse($retVal);
//Maximum of 6 news updates.
for($i=0; $i<6; $i++)
{
//Open the newest news update file
$fs=fopen("news/$retVal[$i]", "r");
//Loads each line of the update into an array
$j=0;
while (!feof ($fs))
{
$buffer[$j] = fgets($fs, 4096);
$j++;
}
//Get the title/headline of the update
$title = $buffer[0];
//Get the actual message of the news update
for($j=1;$j<(count($buffer)-1);$j++)
$body = "$body$buffer[$j]
";
//Get the signature and time for the update
$filemod = filemtime("news/$retVal[$i]");
$filemodtime = date("h:i:sA F j, Y", $filemod);
$sig = "$buffer[$j] - $filemodtime";
?>
A bunch of HTML table code with PHP variables inserted like this: <? echo $title ?>
<?
//Reset some arrays and close the filesteam
unset($body);
unset($buffer);
close($fs);
//Am I allowed to do this?
//I'm closing the For Loop in a separate chunk of php code.
//It seems to work, but would this cause any problems?
}
?>
Some of the code is a little redundant because I rewrote it trying to fix the problem. Thanks in advance.
<?
$handle=opendir("news");
//Loads all the files in the directory
while ($file = readdir($handle))
{
if (($file!=".") && ($file!=".."))
{
$retVal[count($retVal)] = $file;
}
}
//Clean up and sort
closedir($handle);
sort($retVal);
//Reverse it back for my convenience
$retVal=array_reverse($retVal);
//Maximum of 6 news updates.
for($i=0; $i<6; $i++)
{
//Open the newest news update file
$fs=fopen("news/$retVal[$i]", "r");
//Loads each line of the update into an array
$j=0;
while (!feof ($fs))
{
$buffer[$j] = fgets($fs, 4096);
$j++;
}
//Get the title/headline of the update
$title = $buffer[0];
//Get the actual message of the news update
for($j=1;$j<(count($buffer)-1);$j++)
$body = "$body$buffer[$j]
";
//Get the signature and time for the update
$filemod = filemtime("news/$retVal[$i]");
$filemodtime = date("h:i:sA F j, Y", $filemod);
$sig = "$buffer[$j] - $filemodtime";
?>
A bunch of HTML table code with PHP variables inserted like this: <? echo $title ?>
<?
//Reset some arrays and close the filesteam
unset($body);
unset($buffer);
close($fs);
//Am I allowed to do this?
//I'm closing the For Loop in a separate chunk of php code.
//It seems to work, but would this cause any problems?
}
?>
Some of the code is a little redundant because I rewrote it trying to fix the problem. Thanks in advance.
