?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?Easy newb fwrite question.
Author:??(---.towson01.md.comcast.net)
Date:???07-14-03 15:54

Hello, I am trying to make my page write to /data/news.txt when I input to a form. I can get the data to the write place, but it doesn't write correctly. An example of how the news.txt file is split up is like:

Jan 4~This is another news post.
Jan 3~This is a news post.
Dec 31~Welcome.

$fp = fopen("./data/news.txt", "r+");
fwrite($fp, $date);
fwrite($fp, "~");
fwrite($fp, $message);
fwrite($fp, "\n");
fclose($fp);

This only partially works. I want it to basically insert $date~$message on the top line and leave the rest of the file in tact. This is probably a simple answer. Thanks for your time. By the way, if you can also add a check so there are only 3 lines in the file (keeps it at 3 news posts), that would be great but not a necessity. Thanks again.

?Re: Easy newb fwrite question.
Author:??(---.bluecom.no)
Date:???07-15-03 03:11

1. If your site is hosted on a Linux server make sure that you have set the CHMOD to 777 on the news.txt file

2. You need to read the file into your script... have a look at the fread() function in the php manual

3. Replace all your fwrite functions with one, like this:
fwrite($fp, $date."~".$message."\n");

If you have access to a sql database, it would be smart to use it... that way you don't have to lower the security of the site by setting the CHMOD to 777

If you don't have access to a Database, have a look at FlatFile, you still have to change the CHMOD, but you get a lot of sql functions... so that you don't have to delete old news - just make the it retrive the lates new!

Read more on the FlatFile homepage:
http://ffdb-php.sourceforge.net/

Good luck!

Go to Top??|??Go to Topic??|??Threaded View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??

Provided By
Phorum