Ok,
I took a look at that site an "r+" corresponds to what I need. (Open for reading and writing; place the file pointer at the beginning of the file.)
However, now Im having a problem with the news file.
Write news PHP
PHP:
$fp=fopen(NEWS_FILE,"r+");
$formatted=str_replace("\r\n","<br>",$news);
$formatted=str_replace("\n","<br>",$formatted);
$newsto=date("d M Y")."%~#".$title."%~#".$formatted;
fwrite($fp,StripSlashes($newsto)."\n");
Read news PHP
PHP:
$startpage=$_GET['page'];
$xnews=file(NEWS_FILE);
$xnews=array_reverse($xnews);
$startpage-=1;
$ubound=count($xnews);
// Next / Prev Buttons
if($startpage<0 || $startpage>=$ubound/PERPAGE) $startpage=0;
if (PERPAGE<$ubound)
if($startpage==0) echo "";
else echo "Previous Link";
if($ubound>PERPAGE)
for($j=1;$j<=ceil($ubound/PERPAGE);$j++) {
if($j==$startpage+1)
echo "";
else
echo "";
}
if(PERPAGE<$ubound)
if($startpage+1>=$ubound/PERPAGE) echo "";
else echo "Next Link";
//below we format the news we need and print it to webpage
for($i=$startpage*PERPAGE;$i<$startpage*PERPAGE+PERPAGE && $i<$ubound;$i++)
{
$crtsplit="";
$crtsplit=explode("%~#",$xnews[$i]);
echo "<br><br><table border=\"0\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"#000000\" width=\"100%\"><tr><td>";
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" bgcolor=\"#FF9DD0\" width=\"100%\"><tr><td align=left>";
echo "<font color=\"#ffffff\"><center><b>$crtsplit[1]</b></center></font>";
echo "</td></tr></table></td></tr></table><br><br>$crtsplit[2]<br><br>";
}
the news file format is supposed to be:
DATE%~#TITLE%~#CONTENT
DATE%~#TITLE%~#CONTENT
But whenever I add a news using the add news, it always gets overwritten.
------------------------------------------
29 Oct 2003%~#test1%~#test1
------------------------------------------
becomes
------------------------------------------
29 Oct 2003%~#test2%~#test2
------------------------------------------
instead of
------------------------------------------
29 Oct 2003%~#test2%~#test2
29 Oct 2003%~#test1%~#test1
------------------------------------------