<?php
if(!file_exists("comments.txt"))
{
$handle=fopen("comments.txt","w+");
fclose($handle);
}
echo "<form method=\"post\">
Name: <input type=\"text\" name=\"name\"><br>
Comment:<br>
<textarea cols=\"50\" rows=\"4\" name=\"comment\"></textarea>
<input type=\"submit\" value=\"Send!\">
</form>\r\n";
if(isset($_POST['name']) && isset($_POST['comment']))
{
$rep=array('<'=>'<','>'=>'>','|'=>'&#124;');
$name=strtr($_POST['name'],$rep);
$comment=strtr($_POST['comment'],$rep);
$comment=preg_replace('/(\r\n|\r|\n)/','<br>',$comment);
$file=file("comments.txt");
$handle=fopen("comments.txt","w+");
fwrite($handle,"$name|$comment|\r\n");
for($i=0;$i<sizeof($file);$i++)
{
fwrite($handle,$file[$i]);
}
fclose($handle);
}
$file=file("comments.txt");
for($i=0;$i<sizeof($file);$i++)
{
list($name,$comment)=explode("|",$file[$i]);
echo "<b>$name</b><br>
$comment<br><br>";
}
?>