...

View Full Version : erasing txt file before writing new info



boeing747fp
12-20-2003, 11:00 PM
i have a script that writes the content from a textarea to a .txt file, but i want it to clear the txt file before posting new info into it......


<?php
$File = "top30message.txt";
$Open = fopen($File, "a");
if ($Open){
$message = $_GET['message'];


fwrite($Open, "$message");
fclose ($Open);
}
?>

SDP2006
12-21-2003, 12:08 AM
It will rewrite the file automatically.

missing-score
12-21-2003, 01:31 AM
$Open = fopen($File, "w");

SDP2006
12-21-2003, 02:23 AM
Yeah use w mode. It will automatically rewrite the file with the contents of the textarea.

boeing747fp
12-21-2003, 02:29 AM
how do i echo the info from a txt file?

missing-score
12-21-2003, 03:50 AM
to do this you would need to read the text file. There are many ways to do this, and this is how i usually do it:




$fh = fopen("filename.txt", "r");

while(!feof($fh)){

echo fgets($fh, 4096);

}

fclose($fh);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum