random1 Posted April 2, 2008 Share Posted April 2, 2008 I have the following code: $output = "test file\n output for \n\nnew lines"; $outputfile = "tester.txt"; // Write the file to the file system try { $fh = fopen($outputfile, 'w') or die(); fwrite($fh, $output); fclose($fh); } catch (Exception $ex) { return false; } // file created return true; This creates the file but with no new lines. This creates the file correctly (with new lines) when I change $outputfile to something like 'tester.htaccess'. Any ideas for writing new lines '\n' to .txt text files? Link to comment https://forums.phpfreaks.com/topic/99171-writing-new-lines-in-txt-files/ Share on other sites More sharing options...
trq Posted April 2, 2008 Share Posted April 2, 2008 $fh = fopen($outputfile, 'a') or die(); // note the a switch Link to comment https://forums.phpfreaks.com/topic/99171-writing-new-lines-in-txt-files/#findComment-507371 Share on other sites More sharing options...
random1 Posted April 2, 2008 Author Share Posted April 2, 2008 Found out that when running PHP on Windows and writing to a text file you need to do '\r\n' instead of '\n' for new lines. Link to comment https://forums.phpfreaks.com/topic/99171-writing-new-lines-in-txt-files/#findComment-507390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.