Ahah! That's what I was thinking, thatnks for helping me clear that up! John Holmes wrote:
>>I have a chat script that I downloaded and according to the license I >>can modify it as much as I want, and I'm a little stuck on a simple >>modification I want to make. When you type in a message it stores in >> >> >in > > >>a file called text.php and then the chat page does an include call for >>the text.php file. Currently, the writer of this script has it setup >> >> >so > > >>all new text added is placed at the begining of the file using the >> >> >"w+" > > >>command, according to php.net with fopen if I switch the "w+" to "a+" >> >> >it > > >>shoudl place the new data at the end of the file. However, when I make >>this switch, the data is still being placed at the begining of the >>text.php file. I've including the portion of the script that writes to >>text.php can someone help me find what I'm not seeing? >> >>$filename = "text.php"; >> $fileAr= file($filename); >> >> > >It's reading the whole file into an array here. The newest lines will >still be first. > > > >> exec("cat /dev/null > '$filename'"); >> $fd = fopen( $filename, "w+" ); >> >> > >This opens the file and truncates it to zero length. > > > >> $filemessage = "<a >> >> >> >> >href=\"javascript:launcher('profile.php?username=$username');\"><B>$user >na > > >>me</B></a>: >>"; >> $filemessage .="<font >>color=\"$fcolor\">$chat</font><BR>\n"; >> fputs($fd,$filemessage); >> >> > >This write the new, formatted message. > > > >> $numLines = 20; >> for ($i=0;$i<$numLines;$i++) { >> fputs($fd,$fileAr[$i]); >> >> > >And then write the first 20 lines of the file. > > > >> } >> fclose( $fd ); >> >> > >So, if you want it in the new format of newest chat last in the file, >then use the same script, but fputs() the 20 old lines first, then the >new line. Just change the order. > >This would work for you: > >$numLines = 20; >$filename = "text.php"; >//read whole file >$fileArr = file($filename); >//open file and truncate to zero >$fp = fopen($filename,"w+"); >//write 20 lines of old file to new file >fputs($fp,array_slice($fileArr,0,$numLines); >//format $message >//write message to file >fputs($fp,$message); >//close file >fclose($fp); > >Adapt to your needs... > >---John Holmes... > > > >