Hello
I have created a flat file chat, but I have some troubles to solute before upload:
1. Every time the script updates (which it does every 8 second) the last input is repeated. How can I avoid this repeate whithout canceling my update?
2. I would like the inputs to be sorted after date - rsort($ar) or sort($ar) does not work in this case, because it sorts alfabetic and then date.
3. Is it possible to have a limit of lines in the text file? I have tried to set 100 as limit in the for-loop, but then I have at lot of -> and empty space in the bottom of the textarea. Moreover there can still be far more than 100 lines in the textfile.
Greetings from Jan
My script follows here:
Function ShowText(){
$ar=file("textfile.txt");
for($i=0;$i<100;$i++){
list($data[date],$data[name],$data[text])=explode("|",$ar[$i]);
rsort($ar);
print "$data[date]"." "."$data[name]"." -> "."$data[text]";
}
}
Function WriteData(){
global $name,$text;
if ($action="submitdata"){
print "<form action=\"$PHP_SELF\" method=GET>";
print "<INPUT TYPE=\"hidden\" NAME=\"action\" VALUE=\"submitdata\">\n";
print "Name: ";
print "<input type=text name=name value='$name' size=10 maxlength=10>";
escapeshellcmd($name);
print " ";
print "Text: ";
print "<input type=text name=text size=40 maxlength=160>";
escapeshellcmd($text);
print " ";
print "<input type=submit value=\"Submit\">";
print " ";
print "<input type=reset value=\"Reset\">";
print "</form>";
$dato=date("H:i:s");
$line="$date|$name|$text\n";
$fp=fopen("textfile.txt","a");
fwrite($fp,$line);
fclose ($fp);
}
}
print "<TABLE cellspacing=0 cellpadding=1 border=0>";
print "<TR><TD width=\"570\" align=left valign=top>";
print "<TEXTAREA name=tekst cols=69 rows=14>";
ShowText();
print "</TEXTAREA>";
print "</TD></TR>";
print "<TR><TD>";
print "<BR>";
print "</TD></TR>";
print "<TR><TD>";
WriteData();
print "</TD></TR>";
print "</TABLE>";