News using text files
Posted: Mon Jun 24, 2002 4:57 am
I want to make a news page using text files, each new line bieng a variable (title, name, date, author etc...).
I have the display part down, but i am making a submit page, and here's where the trouble is:
I want my script to check if a file exists or not, starting with n000.nwz, and it it exists go on to look at n001.nwz, and if that exists to check if n003.nwz exists and so on until the file doesn;t exist, create a new file called n004.nwz (or whataver the next number is) and add the appropriate info.
Code:
I have the display part down, but i am making a submit page, and here's where the trouble is:
I want my script to check if a file exists or not, starting with n000.nwz, and it it exists go on to look at n001.nwz, and if that exists to check if n003.nwz exists and so on until the file doesn;t exist, create a new file called n004.nwz (or whataver the next number is) and add the appropriate info.
Code:
Code: Select all
$file = "news\\n000.nwz";
$i = 0;
while (file_exists($file)) {
$i++;
if ($i < 10) {
$i_o = $i;
$i = 0;
$i .= $i_o;
}
if ($i < 100) {
$i_o = $i;
$i = 0;
$i .= $i_o;
}
$file = "news"e;;
$file .= "n";
$file .= "$i";
$file .= ".nwz";
}
if (!file_exists($file)) {
$news = "
$HTTP_POST_VARSїtitle]
$HTTP_POST_VARSїdate]
$HTTP_POST_VARSїtime]
$HTTP_POST_VARSїname]
$HTTP_POST_VARSїbody]
";
$filepath = fopen ($file, "w+");
fputs ($filepath, $news);
fclose ($filepath);
echo "Created $file";
}