Author Topic: I'm stuck with a simple thing :( (shoutbox)  (Read 1176 times)

Offline Wakish

  • Level 14
  • *
  • Posts: 111
  • Reputation: +0/-1
    • View Profile
    • Wakish Wonderz
I'm stuck with a simple thing :( (shoutbox)
« on: June 24, 2007, 12:40:31 PM »
I'm coding something like a shoutbox..
My problem is that I need someone to be able to post a message including several lines:
For e.g:
line 01
line 02
line 03

My code is displaying the above in this fashion:
line 03
line 02
line 01

The code that does this is:
Code: [Select]
// this function is within a class

function display()
{ $arrayBuffer = file("file.txt");

while($i--)
{ //breaks string into sub-arrays
$temp = trim($arrayBuffer[$i]);
$arraySub = explode("",$temp);

$date = $arraySub[0];
$time = $arraySub[1];
$this->user = $arraySub[2];
$this->text = $arraySub[3];  //this is my problem

echo "$this->text";
}
}

Note:
=> I'm using a text file to store the contents.. I know with a DB this might be solved, but I want to achieve this with a simple text file
=> You can have a look at the "raw" demo here: http://wakish.info/shout/

Please can someone help me?
Thanks!
« Last Edit: June 24, 2007, 12:49:38 PM by wakish »

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: I'm stuck with a simple thing :( (shoutbox)
« Reply #1 on: June 24, 2007, 01:05:39 PM »
Try adding this line after $arrayBuffer = file("file.txt"):

$arrayBuffer = array_reverse($arrayBuffer);


I think the problem might be with how you are writing to the text file. If you don't want it to be reversed in the text file as well, you should write to the file by using something like this, instead of appending to the file:

$previousText = file("file.txt");
$newFile = array_push($previousText, $newline, $newline2, [$newline3...]);
//Then here you over-write the file

Offline Wakish

  • Level 14
  • *
  • Posts: 111
  • Reputation: +0/-1
    • View Profile
    • Wakish Wonderz
Re: I'm stuck with a simple thing :( (shoutbox)
« Reply #2 on: June 24, 2007, 01:15:22 PM »
Try adding this line after $arrayBuffer = file("file.txt"):

$arrayBuffer = array_reverse($arrayBuffer);


I think the problem might be with how you are writing to the text file. If you don't want it to be reversed in the text file as well, you should write to the file by using something like this, instead of appending to the file:

$previousText = file("file.txt");
$newFile = array_push($previousText, $newline, $newline2, [$newline3...]);
//Then here you over-write the file

1) For the reverse, I've already tried this, in vain :(
2) for the push, I dnt have the values for $newline, $newline2, $newline3... they are in the file..

When I explode the subarray which contains the multi-line comments by a user, basically, the $text is pointing to the first line and ommitting the strings that comes on a newline..
I have also saved the contents of this subarray, and the contents are saved in the expected(orderly) manner, but only when printing on the screen that it is not as desired..
« Last Edit: June 24, 2007, 01:17:38 PM by wakish »

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: I'm stuck with a simple thing :( (shoutbox)
« Reply #3 on: June 24, 2007, 03:18:43 PM »
Oh, ok...

btw, for 2), the $newline is the new text that the user submits to the form when posting a new message, it's not part of the code you posted.

Offline Wakish

  • Level 14
  • *
  • Posts: 111
  • Reputation: +0/-1
    • View Profile
    • Wakish Wonderz
Re: I'm stuck with a simple thing :( (shoutbox)
« Reply #4 on: June 25, 2007, 08:13:02 AM »
Oh, ok...

btw, for 2), the $newline is the new text that the user submits to the form when posting a new message, it's not part of the code you posted.

Zeggy thanks a lot for you trying to help, this is really appreciated..
I'm trying another approach to get the result I want..

Btw, zeggy do you know any php board similar to cboard.cprogramming.com ?
Thanks!

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: I'm stuck with a simple thing :( (shoutbox)
« Reply #5 on: June 25, 2007, 09:07:33 AM »
You mean a forum just for PHP, or a forum script in PHP?

http://www.phpfreaks.com/forums/
PHP Freaks seems quite popular, but I don't really go on that forum myself. They used to have a PHP game section, but it looks like they took it off :(

Offline Wakish

  • Level 14
  • *
  • Posts: 111
  • Reputation: +0/-1
    • View Profile
    • Wakish Wonderz
Re: I'm stuck with a simple thing :( (shoutbox)
« Reply #6 on: June 25, 2007, 06:03:19 PM »
You mean a forum just for PHP, or a forum script in PHP?

http://www.phpfreaks.com/forums/
PHP Freaks seems quite popular, but I don't really go on that forum myself. They used to have a PHP game section, but it looks like they took it off :(

A forum of course ;)

Btw, I've been able to solve the coding problem I was having.. I did this: "filtering the string for newlines and replacing each occurence of a newline by a <br> tag" ;)
Cheers!

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Re: I'm stuck with a simple thing :( (shoutbox)
« Reply #7 on: June 26, 2007, 10:41:24 AM »
Haha, glad you fixed it :)

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal