faqts : Computers : Programming : Languages : PHP : Function Libraries

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 8 people (50%) answered Yes
Recently 0 of 4 people (0%) answered Yes

Entry

How can I replace the contents of a file?

Jul 10th, 1999 09:37
Nathan Wallace, Alexander Avilov, Brad Marsh


Check the mode parameter for

    http://www.php.net/manual/function.fopen.php3

    'w' - Open for writing only; place the file pointer at the beginning 
    of the file and truncate the file to zero length. If the file does 
    not exist, attempt to create it. 

Here is an example:

    @$fp = fopen ("$notify", "w");
    fwrite ($fp, $email_file) or die("Couldn't write e-mail file!");
    @fclose ($fp);

This was a script to write a file to be emailed. Every time it was
called the $email_file variable was written to $notify (a path/file name
combo).