I have a "admin" page where a user can type in a news update.
When submitting this update, I call for a admin.php file.
In admin.php I retrieve the information typed in the previous page and store in in a variable $ni (NewsInput).
Now.... I'm putting the new input FIRST in the news file. To do that I do the follwing:
- open news text file and store it using fread() into variable $old_news. Then I close the file.
- Retrieve todays date, and store it into the variable $today.
Now the follwing code:
@ $fp = fopen("data/news.txt","w");
fwrite($fp, $today);
fclose($fp);
@ $fp = fopen("data/news.txt","a");
fwrite($fp, $ni);
fwrite($fp, $old_news);
fclose($fp);
The problem is when I write the date to the file, it does NOT append a \n in the textfile. Neither does it do that when I append the $ni file. I've tried fwrite($fp, $today."\n") and it doesn't work - only almost. I get a weird square in my text file, and that causes problems reding the file.
:: Reading the file ::
I display the news in a table. So I read line by line, to identify if a line is a date. If it is, it goes in the left column. Other text goes in the right column.
But without the \n in my textfiles, I have text AND date on the same line - and my method doesn't understand ANYTHING.
So how can I append the "invisible" \n when writing and appending to file????