here is a script that uses a text file named comments.txt:
an example form:
HTML Code:
<form action="submit.php" method="post">
Name: <input type="text" name="name"><br>
Comment:<br>
<textarea name="comments"></textarea>
<input type="submit" name="submit" value="Send">
</form>
submit.php (comments.txt must already be created):
PHP Code:
<?php
if(isset($_POST['submit']) && $_POST['name'] != null && $_POST['comments'] != null) {
$file=fopen("comments.txt","r+");
$contents=fread($file,filesize("comments.txt")+1);
$contents=$contents."\n[".$_POST['name']."]".$_POST['comments'];
fwrite($file,$contents);
fclose($file);
}
?>
read.php:
PHP Code:
<?php
$format=Array(
'<table width="100%" align="center" border="0">\n',
'<tr>\n<td><b>',//beginning tags for the name
'</b></td>\n',//ending tags for the name
'<td>',//beginning tags for the comment
'</td></tr>',//ending tags for the comment
'</table>'
);
$contents=file("comments.txt");
$formated_comments=$format[0];
for($a=0;$a<count($contents);$a++) {
$formated_comments.=preg_replace("^/\[(.*?)\](.*?)/$",$format[1].'$1'.$format[2].$format[3].'$2'.$format[4],$contents[$a]);
}
$formated_comments.=$format[0];
?>
example page (will display the comments):
Code:
<html>
<head>
</head>
<body>
<?php
include("read.php");
echo $formated_comments;
?>
</body>
</html>
Bookmarks