Results 1 to 3 of 3

Thread: [RESOLVED] I need "fwrite" to destroy contents of file

  1. #1

    Thread Starter
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Resolved [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???

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3

    Thread Starter
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: I need "fwrite" to destroy contents of file

    Thanks! I tried other flags and works "+w"

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width