TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-26-2009, 10:43 PM   #1 (permalink)
The Visitor
 
Join Date: Oct 2009
Posts: 3
Thanks: 0
gallienne09 is on a distinguished road
Default 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>
gallienne09 is offline  
Reply With Quote
Old 10-27-2009, 01:58 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

php Code:
$arr = file( YOUR_FILE );
$arr = array_reverse( $arr );
delayedinsanity is offline  
Reply With Quote
Old 10-27-2009, 02:17 AM   #3 (permalink)
The Visitor
 
Join Date: Oct 2009
Posts: 3
Thanks: 0
gallienne09 is on a distinguished road
Default

Thanks for the code. could you elaborate on this code as to where to use it in my code above. thanks in advance
gallienne09 is offline  
Reply With Quote
Old 10-27-2009, 03:22 AM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

That takes all the fun out of learning. :)

php Code:
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);

Would be...

php Code:
$myFile = 'testFile.txt';
$theData = array_reverse( file( $myFile ) );

foreach ( $theData as $row )
    echo $row . '<br />';

Or however you wish. There's about 3,141.59265 ways to do anything in PHP.
delayedinsanity is offline  
Reply With Quote
Old 10-27-2009, 06:14 AM   #5 (permalink)
The Visitor
 
Join Date: Oct 2009
Posts: 3
Thanks: 0
gallienne09 is on a distinguished road
Default

Thank You very much. Works a treat, didnt relise how easy that was gonna be.

cheers
gallienne09 is offline  
Reply With Quote
Old 03-30-2013, 07:56 AM   #6 (permalink)
The Acquainted
 
Join Date: Mar 2013
Posts: 131
Thanks: 1
caiyanfang is on a distinguished road
Default

'Lindsay's been telling everyone that she moved to Ny because she was sick of ralph lauren outlet online la. But that's simply not true, she so want to move back gulf of mexico, but she won't.

'In the past, Lindsay has were able to rope in anyone to co-sign out on leases because her credit score means she aren't going to get approved in her name alone. ralph lauren polo outlet shop

'However, she couldn't verify anyone polo ralph lauren outlet online willing accomplish this now as brand-new areas such as burned so any one of her friends and are associates. '
caiyanfang is offline  
Reply With Quote
Old Today, 11:58 AM   #7 (permalink)
The Wanderer
 
programmingservices's Avatar
 
Join Date: Dec 2012
Posts: 12
Thanks: 0
programmingservices is on a distinguished road
Default

I think this is the best tutorial info regarding programmer; I really like to read it; and I hope it’s very helpful and useful to me, Thanks sharing for programmer; great going.
__________________
ASP.NET Development India
programmingservices is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i display on a php file the content of a text document chikooo Absolute Beginners 13 01-29-2013 11:44 AM
Read Text File in Reverse buildakicker General 9 11-26-2008 06:43 PM
Make array with txt file content Peuplarchie Absolute Beginners 2 07-17-2008 06:27 PM
Echoing Text File Rows into Array Display... buildakicker General 11 02-04-2008 07:17 PM
Make Your Own PHP Flash Player Which You Can Pass a File Variable with Preview!!!! thegrayman Tips & Tricks 2 12-12-2007 12:44 AM


All times are GMT. The time now is 05:33 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design