Hi everyone!
Im trying to code a script that goes out and searches in a directory for files ($username_$date(in epoch).bcu) then does the neccessary things and prints them out in order from the latest (ie: yesterday) to the earliest (ie:1969). Unfortunatley, my web hosts are running some wierd software that when i do a readdir cmd, it returns the files in no particular order (ie: 5,2,6,7,3,1,4) but instead of being random, they are in no particular order consistantly (i think that it is this way with Apache).
So, as everyone knows, I have to sort the values, either before I handle the file or after. This presents a problem because I dont have much to go on other than the epoch date in the filename.
I have tried throwing all the values in to an array, but when it sorts, somehow it doesnt come out.
Please Help!!! This is the code that I have so far that has not worked:
First I want to open the directory:
$num = 1;
$handle=opendir('.');
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != ".." && ereg(".bcu", $file ) ) {
Then I need to explode the filename, giving me the username and date:
$user_date = explode("_", $file);
//$user_date[0] = $username
//$user_date[1] = $date.bcu
$date = explode(".", $user_date[1]);
//$date[0] = "041501"
//$date[1] = bcu
$rdate = $date[0];
$username = $user_date[0];
$fp = fopen( $file, "r" );
Then I open the file and get the contents. The contents should be formatted as follows:
Title | Info Image | Text
$info = fread( $fp, filesize( $file ) );
fclose( $fp );
$info = explode( "|", $info);//$info[0] = title, $info[1] = topic, $info[2] = article
Then what I do is throw the HTML code into a crudely assembled array with a number starting with 1 then ++ to it:
$html[$num] = "<epoch=\"$rdate\"><table width=\"452\" border=\"2\" cellspacing=\"0\" cellpadding=\"0\" align=\center\" bordercolor=\"#999999\">
<tr>
<td bgcolor=\"#999999\" height=\"3\"><img src=\"/images/spacer.gif\" width=\"10\" height=\"10\">$info[0] </td>
</tr>
<tr>
<td height=\"159\" bgcolor=\"#FFFFFF\" bordercolor=\"#FFFFFF\">
<div align=\"left\">Posted
by $username on ".date("m/d/y", $rdate)."<br>
$username says: <img src=\"/images/topics/$info[1].gif\" align=\"right\"> "$info[2]."</div>
</td>
</tr>
</table><br>";
$num ++;
}
}
closedir($handle);
Now I sort the values of all of the entries using the Natural Sort method:
natsort( $html );
Then I use crude method to retrieve all of the entries, Num is the number of entries:
while( $num > 0 )
{
$html[$num] = stripslashes($html[$num]);
$html[$num] = stripslashes($html[$num]);
print $html[$num];
$num -= 1;
}
Now... all of this mumbo jumbo SHOULD work... yet doesnt... If you have any tips, hints or anything that I have missed...
please reply to this topic....
Thanks so much!!!