|
-
Jul 15th, 2007, 10:18 AM
#1
Thread Starter
Addicted Member
[RESOLVED] I need "fwrite" to destroy contents of file
Hi!
I'm using this write code:
PHP Code:
$nom = $_GET["name"];
$file = fopen("file.txt", "w");
fwrite($file, $nom);
fclose($file);
But I need that the contents of file.txt destroy and write the new value, as given by $nom...any ideas???
-
Jul 16th, 2007, 12:10 AM
#2
Re: I need "fwrite" to destroy contents of file
That's what mode 'w' should do, yes. What is it doing instead?
Edit: unless you need to control when the file is opened and closed, you should prefer file_put_contents instead:
PHP Code:
file_put_contents('file.txt', $nom);
That will overwrite the contents, unless you specify FILE_APPEND as the optional third $flags argument.
-
Jul 18th, 2007, 09:24 AM
#3
Thread Starter
Addicted Member
Re: I need "fwrite" to destroy contents of file
Thanks! I tried other flags and works "+w"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|