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!

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");
?>

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!

Archived

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

×
×
  • 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.