jeff5656 Posted April 9, 2009 Share Posted April 9, 2009 I have a log file to log ip addresses but how do I add a carriage return so every log entry is put on a new line? $logged_string = $_SERVER['REMOTE_ADDR'] . "|" . date("j M Y g:i a"); $file = fopen("userIP.log", "a"); fputs($file, $logged_string, strlen($logged_string)); fclose($file); Quote Link to comment https://forums.phpfreaks.com/topic/153359-solved-carriage-return/ Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 Add a newline \n $logged_string = $_SERVER['REMOTE_ADDR'] . "|" . date("j M Y g:i a") . "\n"; Quote Link to comment https://forums.phpfreaks.com/topic/153359-solved-carriage-return/#findComment-805718 Share on other sites More sharing options...
jeff5656 Posted April 9, 2009 Author Share Posted April 9, 2009 Hi, That works but interestingly it doesn't work in notepad, only if you read the log file in wordpad. I guess notepad can't read the line break character. Quote Link to comment https://forums.phpfreaks.com/topic/153359-solved-carriage-return/#findComment-805724 Share on other sites More sharing options...
nankoweap Posted April 9, 2009 Share Posted April 9, 2009 Hi, That works but interestingly it doesn't work in notepad, only if you read the log file in wordpad. I guess notepad can't read the line break character. nah. winderz is a different beast. new lines are a combination of carriage return and newline whereas unix-based systems are typically newline only. there's probably a php function for this, but i'm a php noob and don't know. change "\n" to "\r\n" to the code and see what happens. jason Quote Link to comment https://forums.phpfreaks.com/topic/153359-solved-carriage-return/#findComment-805731 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.