Jump to content

How to insert a return or line break in txt files using php?? QUICK QUESTION


snowman15

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.