Page 1 of 1

need help with fwrite() - a new line every entry...

Posted: Sat Jun 17, 2006 11:29 am
by The-Master
hi, i need some help with fwrite(), lets say i have this code:

Code: Select all

function log ($text) 
{
$file = fopen('log.txt', 'a', 1);
fwrite($file, $text);
fclose($file);
}
every time i write this:

Code: Select all

log("this is a log entry");
i add a new entry but the problem is that every entry is added at the same line...
so if i do this:

Code: Select all

log("this is a log entry ");
log("this is the second log entry ");
log("this is the third log entry");
the file looks like this:

Code: Select all

this is a log entry this is the second log entry this is the third log entry
and i want it to be:

Code: Select all

this is a log entry
this is the second log entry
this is the third log entry
what do i need to add fwrite("... here"); to make every entry in its own line...

Posted: Sat Jun 17, 2006 11:39 am
by printf
Add a line ending to the text, or define one in the function it self...

Code: Select all

// Unix/Linux

log("this is a log entry\n"); 
log("this is the second log entry\n"); 
log("this is the third log entry\n"); 

// Max/OSX

log("this is a log entry\r"); 
log("this is the second log entry\r"); 
log("this is the third log entry\r"); 


// Windows

log("this is a log entry\r\n"); 
log("this is the second log entry\r\n"); 
log("this is the third log entry\r\n");
pif!

Posted: Sat Jun 17, 2006 12:10 pm
by The-Master
thanks! you know i tried the "\n" new line as i remembered from C's syntax...
i forgot the "\r"...