View Single Post
Old Jul 23rd, 2004, 9:41 AM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Here's a little diddy, that i whiped up...havn't tested it though.

get you script that inputs the news into the file to seperate the news with a line that contains somthing like ^&.

<?PHP

$textfile = "Your/Path/to/file"; //set the path to the file here.
if ($text = @file("textfile")) //Don't display errors on file open
{
     $y = 0; //set the height var. for the array.
     for ($x=0; $x<count($text); $x++) 
     {
           $tmp = $text[$x];
           if ($tmp == "^&")
           {
                  //we have a line break
                  $textarr[$y][$x] = $text[$x]; //we will need to have the 
                                       //line break later when                                                          
                                       //outputing.
                  $y++;
            }
           else
           {
                 //we have text that is still part of a new item.
                 $textarr[$y][$x] = $text[$x]; 
            }
      }
      //Now to output the text
      for ($x=count($text); $x<>0; $x--)
      {
            if ($textarr[$y][$x] == "^&") //we have a line brake.
            {
                  $y--;
            }
            else
            {
                 echo $textarr[$y][$x];
             }
       }
}
?>

Anyways, That's how i would do it, but kurifu is right
Quote:
The easiest method is just to write new data to the front of the file.. which means everytime you want to write to a file, write to a temporary file, copy the old news file the the end of the temp file, then move the temp file to the original file's place.
Note i havn't tested this code yet, so it might be right or wrong. Probally got some errors in it. And when your putting the news into your file only make a line brake at the top of your news text that you inputting, otherwise you'll get werid stuff happening when you output the code because of the array.

Good luck and hope my code is right...heh
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote