Jump to content

How To Write A New Line Character To A File?


robinbell

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...