Re: [PHP] Problems after reversing a guestbook

2001-05-01 Thread Jason Stechschulte

On Sun, Apr 29, 2001 at 01:03:15AM +0200, Mogens Nielsen wrote:
 Now the problem: If I post a message with a line of text, a newline (as in
 hitting the return-key), some more text and newlines, these
 newline-separated text-lines show before the posting itself after reversing
 because they are independent elements in the array.
 How can I fix this

The short answer is use a database.  The long answer is to write your
function to reverse the array.  You could have the original array passed
to the function and your function return a reversed one.  In your
function, you would have to do some checking.  If the index is a new
entry into your guestbook, then create a new index in the new array.  If
not, just prepend the text to the last index of the array.

I'm imaging that your text file is delimited by something.  You may want
to explode each line so you can tell if it belongs together or not. 

-- 
Jason Stechschulte
[EMAIL PROTECTED]
--
double value;/* or your money back! */
short changed;   /* so triple your money back! */
 -- Larry Wall in cons.c from the perl source code

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Problems after reversing a guestbook

2001-04-28 Thread Mogens Nielsen

Hey there!

This is my absolutely first time posting in a newsgroup, so be nice please
; )
I've written a guestbook, and in an attempt to get the newest entries first
I reversed the guestbook-txt-file. Like so:
$tabell = file( gjestebok.txt );
$revtab = array_reverse( $tabell );

$antall = count( $revtab );

$i = 0;

if( !( $fil = fopen( guestbook.txt, r+ ) ) )
die();

while( $i  $antall )
{
  fwrite( $fil, $revtab[$i] );
  $i++;
}

fclose( $fil );

Now the problem: If I post a message with a line of text, a newline (as in
hitting the return-key), some more text and newlines, these
newline-separated text-lines show before the posting itself after reversing
because they are independent elements in the array.
How can I fix this


Mogens



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]