Hi everyone. I'm new to these forums so please go easy on me. I've been doing PHP all day so I think I have a good amount of understanding about it... anyway, I'm trying to make a news-posting system and it's all working fine and dandy except one thing (I'll get to it). Here's the system:
http://wi.verdagon.com/post.php
You enter a 10-character string for the date (like 99-99-9999) and whatever you want for the rest, and it perfectly inserts that news post into http://wi.verdagon.com/01News.php
Except there's one problem. It inserts the news at the bottom of the page, under all the old posts. I want the new news to appear first, before all the older posts.
Here's how I set it up: The post.php page is just a form, with the "POST" action that posts to http://wi.verdagon.com/addnews.php and then the addnews.php takes what and puts the cool fancy tables around them. Then it adds the result to http://wi.verdagon.com/news.txt AT THE END of it.
The way http://wi.verdagon.com/01News.php works is it uses the "require()" function to include news.txt.
Here's the code for the addnews.php page (well, the important part):
<?php
$filename = "news.txt";
$somecontent = "<tr><td><a name=5></a>".$begin.$date.$resume."<b>Subject: ".$subject."</b><br>".$news."<br><div align=right>- ".$name."</div>".$end."</td></tr>\n";
if (is_writable($filename))
{
if (fwrite($handle, $somecontent) == FALSE)
{
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote to $filename";
fclose($handle);
}
echo "<br><br><br>", $somecontent;
?>
Basically, I need to know how to insert text to the beginning of a text file. How can I do this? Thank you all so much in advance for helping me.