snowman15 Posted September 2, 2007 Share Posted September 2, 2007 I am trying to log certain times in a txt file. heres my code: list($hour, $min, $sec) = explode(':', date('h:i:s')); $file = fopen("log.txt","a+"); $time= date("F j, Y, g:i a"); fwrite($file, $time); example of txt log after 3 entries: 12:3412:3512:36 (3 times all together.) what i want: 12:34 12:35 12:36 Everytime I go on the site, it logs my time but it logs it on the same line and i want a line break. How do i insert code at the end of the fwrite() to make a line break inside of the txt file? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/67686-how-to-insert-a-return-or-line-break-in-txt-files-using-php-quick-question/ Share on other sites More sharing options...
Fadion Posted September 2, 2007 Share Posted September 2, 2007 $time= date("F j, Y, g:i a") . "<br />"; Quote Link to comment https://forums.phpfreaks.com/topic/67686-how-to-insert-a-return-or-line-break-in-txt-files-using-php-quick-question/#findComment-340011 Share on other sites More sharing options...
GingerRobot Posted September 2, 2007 Share Posted September 2, 2007 Try: <?php fwrite($file, $time."\n"); ?> GuiltyGear: <br /> is an HTML tag to create a new line on a webpage. It is differant from the newline character (\n) needed in this case. Quote Link to comment https://forums.phpfreaks.com/topic/67686-how-to-insert-a-return-or-line-break-in-txt-files-using-php-quick-question/#findComment-340020 Share on other sites More sharing options...
snowman15 Posted September 2, 2007 Author Share Posted September 2, 2007 thanks, thats what i was looking for. Quote Link to comment https://forums.phpfreaks.com/topic/67686-how-to-insert-a-return-or-line-break-in-txt-files-using-php-quick-question/#findComment-340021 Share on other sites More sharing options...
Barand Posted September 2, 2007 Share Posted September 2, 2007 For complete answer for all 'Nix systems <?php fwrite($file, $time."\n"); ?> Win systems <?php fwrite($file, $time."\r\n"); ?> Mac systems <?php fwrite($file, $time."\r"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67686-how-to-insert-a-return-or-line-break-in-txt-files-using-php-quick-question/#findComment-340079 Share on other sites More sharing options...
Crew-Portal Posted September 2, 2007 Share Posted September 2, 2007 For complete answer for all 'Nix systems <?php fwrite($file, $time."\n"); ?> Win systems <?php fwrite($file, $time."\r\n"); ?> Mac systems <?php fwrite($file, $time."\r"); ?> Wow could'nt make that any simpler! Thanks I was also one for wondering why my txt files didnt make a line break when using /n But now I know! Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/67686-how-to-insert-a-return-or-line-break-in-txt-files-using-php-quick-question/#findComment-340083 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.