robinbell Posted January 27, 2009 Share Posted January 27, 2009 Hi,Another basic question. I'm trying to write a message to a text file to try to track down an intermittent problem.I'm using the file_put_contents function, as so: file_put_contents("mylog.txt","$loggedtime $filechattime $filechatnick $filechattext $users $id",FILE_APPEND); where $loggedtime etc are variables I want to log.My problem is that the output file, when viewed with notepad, does not have each logged entry on a separate line - it all runs together.Can anyone help, please? Link to comment Share on other sites More sharing options...
jeffman Posted January 27, 2009 Share Posted January 27, 2009 file_put_contents("mylog.txt","$loggedtime $filechattime $filechatnick $filechattext $users $id\n",FILE_APPEND); Link to comment Share on other sites More sharing options...
robinbell Posted January 28, 2009 Author Share Posted January 28, 2009 OK!I actually got it to work by splitting the code over 2 physical lines, but was sure that there was a better way. When I look at the output after adding "\n" now in Notepad, there is a "square" symbol, rather than a carriage return. However, opening the log file with Wordpad gives the correct display, thanks.Guess I'll just use Wordpad instead of Notepad when checking the log file.Thanks again Link to comment Share on other sites More sharing options...
jeffman Posted January 28, 2009 Share Posted January 28, 2009 I didn't realize that viewing in Notepad was the goal -- I figured it was just a test or something. For most web operations, "\n" is sufficient. If you want a true carriage return, "\r" is your character. Link to comment Share on other sites More sharing options...
robinbell Posted January 28, 2009 Author Share Posted January 28, 2009 Thanks for the suggestion. I changed it from \n to \r but got the same results. No problem, it was just for my own debugging purposes, so it's not important. I'll just open the file with Wordpad rather than Notepad.... Link to comment Share on other sites More sharing options...
jlhaslip Posted January 28, 2009 Share Posted January 28, 2009 \n\r Link to comment Share on other sites More sharing options...
justsomeguy Posted January 28, 2009 Share Posted January 28, 2009 Haha, close guys. It's \r\n. \r\n = Windows \r = Mac\n = Linux/UnixI always wondered how Notepad could get that wrong. I realize it's looking for \r\n, but it seems strange that it wouldn't know what to do with \r unless it was followed by \n, or it wouldn't know what to do with \n unless it was preceeded by \r. Whatever... Link to comment Share on other sites More sharing options...
robinbell Posted January 30, 2009 Author Share Posted January 30, 2009 Thanks for that. It works fine with \r\n in Notepad. One of those odd little quirks that we all know and love with Microsoft.... Link to comment Share on other sites More sharing options...
jeffman Posted January 30, 2009 Share Posted January 30, 2009 Actually, carriage return and newline are the traditional way of doing it, going back to telegraph machines. Think of a typewriter. The carriage must return, but also must roll up a couple notches.By the time Unix came along, that was unnecessary. It was also unnecessary for MS-DOS, I guess, unless maybe they worried about connecting to older printers. Not a bad bet if they wanted to partner with IBM.Apple made their own printers, so they could do what they wanted, I suppose. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.