im using a chat program which is text file based. Currently when i type a message at the send line it adds the message to the top of the file. i want to add the message to the end of the file so that new messages will be displayed from bottom to top
Much like aol chat.
heres a code snipit
$chat = ereg_replace("\"",""",$chat);
$chat = ereg_replace("<","<",$chat);
$chat = ereg_replace(">",">",$chat);
$filename = "text.php";
$fileAr= file($filename);
exec("cat /dev/null > '$filename'");
$fd = fopen( $filename, "a+" );
$filemessage = "<a href=\"javascript:launcher('profile.php?username=$username');\"><B>$username</B></a> : ";
$filemessage .="<font color=\"$fcolor\">$chat</font><BR>\n"; //Here is where text is displayed
fputs($fd,$filemessage);
$numLines = 20;
for ($i=0;$i<$numLines;$i++) {
fputs($fd,$fileAr[$i]);
}
fclose( $fd );
CODE]
from this code can anyone tell me what im doing wrong.
Note the answer may not be in this code as the file is much larger than this