JPark Posted February 22, 2010 Share Posted February 22, 2010 I have a php page with a form that, upon submit, generates a text file of the person's choices -- using it as a flat file. I want to start a new line with each entry so I used \n\r as in $line1= $today."^".$_POST['email']."^".$value; foreach ($sector_numbers as $key => $value) { $line = "{$line1}^{$value}\n\r"; $file_write = fwrite($file_handle, $line); } The problem is that my text file shows little boxes instead of new lines (see attachment). Why? How can I fix it? Thanks! Joe [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/192980-line-breaks-in-a-text-file/ Share on other sites More sharing options...
jl5501 Posted February 22, 2010 Share Posted February 22, 2010 use "\n" by itself should give you the correct newlines Quote Link to comment https://forums.phpfreaks.com/topic/192980-line-breaks-in-a-text-file/#findComment-1016322 Share on other sites More sharing options...
salathe Posted February 22, 2010 Share Posted February 22, 2010 \n\r is not a usual line ending sequence. They're: \r\n - "Windows" \r - "Macintosh" \n - "Unix" Quote Link to comment https://forums.phpfreaks.com/topic/192980-line-breaks-in-a-text-file/#findComment-1016346 Share on other sites More sharing options...
JPark Posted February 23, 2010 Author Share Posted February 23, 2010 \n\r is not a usual line ending sequence. They're: \r\n - "Windows" So \n\r is different than \r\n?? Quote Link to comment https://forums.phpfreaks.com/topic/192980-line-breaks-in-a-text-file/#findComment-1016722 Share on other sites More sharing options...
salathe Posted February 23, 2010 Share Posted February 23, 2010 Very much so. By way of analogy, would you consider the strings "ab" and "ba" to be identical? Quote Link to comment https://forums.phpfreaks.com/topic/192980-line-breaks-in-a-text-file/#findComment-1016724 Share on other sites More sharing options...
JPark Posted February 23, 2010 Author Share Posted February 23, 2010 salathe, Well, I changed the code and tested it and doggonit you are right! While your analogy makes sense NOW, before I was just thinking of them as line breaks in different languages as in "Hi! Hola!" is pretty much the same as "Hola! Hi!" I stand sit corrected. Thanks for clarifying!! Joe Quote Link to comment https://forums.phpfreaks.com/topic/192980-line-breaks-in-a-text-file/#findComment-1016733 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.