Hi!
I'm using this write code:
But I need that the contents of file.txt destroy and write the new value, as given by $nom...any ideas???PHP Code:$nom = $_GET["name"];
$file = fopen("file.txt", "w");
fwrite($file, $nom);
fclose($file);
Printable View
Hi!
I'm using this write code:
But I need that the contents of file.txt destroy and write the new value, as given by $nom...any ideas???PHP Code:$nom = $_GET["name"];
$file = fopen("file.txt", "w");
fwrite($file, $nom);
fclose($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:
That will overwrite the contents, unless you specify FILE_APPEND as the optional third $flags argument.PHP Code:file_put_contents('file.txt', $nom);
Thanks! I tried other flags and works "+w"