Is it possible to make a new line in a text file, while writing using fwrite()? I'm planning to write values to a file, and then retrieve them using file() to store them in an array, but I can't figure out how to get a new line. I've tried concatonating a "\n" onto the backend of the string to be written, but, that just adds a \n to the end of the line. Is there a way to use an ASCII value or something?

    "\n" should work, you might want to try "\r\n" too, it's different between Windows and *NIX.

    Post the code if you still can't figure it out...

      i think he's looking for append.... put "a" in the mode of fopen() then write out \nline\n

        There's a comment on this page (about the 2nd or third comment down) that discusses this issue.

          Here is the quote, may help.

          The way I understand fputs (which is purported as an alias to fwrite which can be "Binary Safe")...
          <pre>$fp = fopen("something.txt","w");
          $string = "Hello World\n"; // escape the slash from being magically
          // being transformed into a newline
          fwrite($fp, $string); // will proccess /n as newline ...
          fwrite($fp, $string, strlen($string)); // will write the entire string to file without changing the '/n'
          // into a single byte for newline on Unix-like machines or CR/LF on Win32 machines

          </pre>

          Hope this helps explain the definition of "could be Binary Safe". This is the reason why you must specify the length!

          --Doug

          There's more on the page.

            Allrighty. I'll try out those solutions and post again if I can't get one to work. BTW, I'm on a *NIX (Linux) system - if that makes significant difference.

              Write a Reply...