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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

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

Post 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...
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post 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!
The-Master
Forum Commoner
Posts: 45
Joined: Sun Aug 07, 2005 9:51 am
Location: Israel

Post by The-Master »

thanks! you know i tried the "\n" new line as i remembered from C's syntax...
i forgot the "\r"...
Post Reply