10-26-2009, 10:43 PM
|
#1 (permalink)
|
|
The Visitor
Join Date: Oct 2009
Posts: 3
Thanks: 0
|
Make a txt file display in reverse
Can some one tell me how to reverse the text file so it displays what goes in last first.
Cheers in advance
here is the code:
<html>
<head>
<title>test Text</title>
</head>
<body>
<div style='overflow:auto; width:230px; height:500px; background-color:orange'>
<fieldset width="200">
<legend>
<b>Message Board:</b>
</legend>
<form method="POST" action="text.php" style="font-family:verdana; font-size:10pt">
Nickname:<br><input type="text" name="name" size="25"/><br>
Comment:<br><textarea name="comment" rows="4" cols="23">
</textarea><br>
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>
</fieldset>
<?php
$date= date("d/m/y");
$name=$_POST['name'];
$comment=$_POST['comment'];
if ($comment != "" )
{
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "<b>Posted: $date</b>\n<br>";
fwrite($fh, "$stringData");
$stringData = "\"$comment\"\n<br>";
fwrite($fh, "$stringData");
$stringData = "<b>By:$name</b>\n<hr>";
fwrite($fh, $stringData);
fclose($fh);
}
else
{
echo "<b style='color:red'>Please fill in all fields!</b>";
}
?>
<?php
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo "
<table border='0' width='210' align='center'>
<tr>
<td style='font-family:verdana; font-size:8pt'>
$theData
</td>
</tr>
</table>
";
?>
<?php
?>
</div>
</body>
</html>
|
|
|
|