Forum Moderators: coopster

Message Too Old, No Replies

Writing lines to a file

         

hannahd

2:24 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



Hello,

I want to create a text file that contains SQL statements line by line.

But instead, it all gets dumped on one line:

This is my script

$file = fopen("dump.sql", "a+");

$str = "\nINSERT INTO table";

fputs($file, $str);

fclose($file);

It seems to completely ignore the \n character. All it does is appends a square to the end of the file. But it doesn't allow you to write on the next line.

What am I doing wrong?

Thanks

Hannah

Zipper

2:39 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



In normal practice, the "\n" goes at the end of the string. If you are not using the file to read it's contents use mode 'a' instead of 'a+'. Also, try opening the text file in WordPad.

hannahd

3:04 pm on Sep 9, 2004 (gmt 0)

10+ Year Member



Thanks Zipper :)

I've found a solution now. The problem was I was using \n instead of \r\n, which should be used under Windows.