Jump to content

Trying to make a simple script but need help.


BorderC

Recommended Posts

It's been a long time since I used php and I lost my book on it. So, here's what I need to do. It's really simple but I forget how.

I want to have a page where someone can go and fill out a form, and have the form write to a file that I can then include (SSI) on another page. This way other admins of my site can put in their name and write "news" for the main page of my site and have it automatically display on the main page. And I want the new news to be written to the top of the file to be included, so it shows up as the most recent post. I've done it before but like I said it has been a long time. like 6 years and I totally forget how to do it and cant find my book  :(
Not really sure what SSI is...

But the rest isn't too difficult:

1. Get the data from the form with $_GET['blah'] or $_POST['poo'] and do any form validation you may want.

2. writing:
$pathToFile = "/news.dat";
$handle = fopen($pathToFile, 'a'); // opens the file for appending
$content = "write me"; // clear your data of line breaks and line ends. (I usually replace it with ":::" or something so I can replace them later)
fwrite($handle, $content); // write to the file
fclose($handle);

3. reading:
$handle = fopen($pathToFile, 'r');
$entries = file($handle); //  reads the file into an array, indexed by new lines
$entries = array_reverse($entries); // reverse the array so new entries appear first
fclose($handle);

4. iterate over the array however you want to display the contents.

Is this what you wanted to do? I would recommend looking at http://www.tizag.com/phpT/fileread.php for more help


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.