bobpatel07 Posted March 3, 2010 Share Posted March 3, 2010 I am a new to php. I am trying to writing to a text file using php. I am able to write to the text file, however when I open the text file using the text editor, it displays raw data on the same line. How can I write data in a text file on the next line? Following is my php code. <?php $myFile = "testFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "Bobby Bopper\n"; fwrite($fh, $stringData); $stringData = "Tracy Tanner\n"; fwrite($fh, $stringData); print "Date is written"; fclose($fh); ?> Text file Bobby BopperTracy Tanner // I used notepad to view. I am also using WAMP server Link to comment https://forums.phpfreaks.com/topic/194000-writing-to-a-file/ Share on other sites More sharing options...
Dennis1986 Posted March 3, 2010 Share Posted March 3, 2010 Use \r\n instead of just \n since you're on a windows system. This equals to hitting enter at the end of a line in notepad. Link to comment https://forums.phpfreaks.com/topic/194000-writing-to-a-file/#findComment-1020893 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.