[PHP] Re: delete file contents before writing?

2002-06-03 Thread Peter

$file_open = fopen($file_name, w);

this will empty the existing file contents then write to the file


Jas [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Not sure how I could do this as I could not find a functions on php.net to
 allow me to first delete the entire contents of a file before writting
the
 changes supplied by a textarea.  Here is what I have thus far:
 Page one - Form:
 ?php
 $file_name = 'blank.php';
 $open_file = fopen($file_name,rw);
 if (!$open_file) {
  die(cannot open $file_name);
  } else {
  $read_file = fread($open_file, filesize($file_name));
   $strip_php = eregi_replace(,a, $read_file);
   fclose($open_file);
  }
 ?
 form name=edit_passwords method=post action=edit_passwords.php
   textarea name=passwords cols=60 rows=7?php echo $strip_php;
 ?/textarea
   br
   input type=submit name=save value=save
 /form
 Page two - open file and write changes:
 ?php
 if (!$passwords) {
  header (Location: index.php);
  } else {
  $file_name= blank.php;
  $file_open = fopen($file_name, r+);
   eregi_replace(a,, $file_open);
   #eregi_replace(\,, $file_open);
   fwrite($file_open, $passwords);
  print ($passwords was written to $file_name); }
 ?
 As of right now it opens the file and writes your changes, however it
simply
 goes to the end of the file then begins writting.  I would like to delete
 the contents of the file, then write the changes.
 Any help or pointers are appreciated!
 Jas





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: Delete File Contents?

2001-12-17 Thread Matt Friedman

http://www.php.net/manual/en/function.ftruncate.php 

 

Chris writes: 

 I've created a program that runs a process then stores the results to a
 file on the server. I would like the file to contain only the most
 recent update, but it seems I can only append to my using fopen. Is
 there a way to open the file and overwrite the data in that file? I've
 considered deleting the file and creating a new one but that seems like
 a lot to do. It would be nice if there were a way to set a pointer to
 the top of the file and overwrite. 
 
 Thanks,
 Chris 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED] 
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]