Jump to content

Archived

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

xtoph

newline in file writing

Recommended Posts

hello.  im new to php so bear with.  i've created a simple hit counter for my personal website that opens a file log.txt and appends a line for each new hit on my opening page.  but the newline isn't registering.  it's all on one line.
there are thousands of people who have had this problem previously, and they all solved it by using html breaks.
that won't work for me because i want to use a text file.  so does anyone know the reason this doesn't work?

[code]fwrite($fh, "hit: ".$ip."    ".$time_date."\n");[/code]

ps. ive tried "\r" as well
using php 5.0.4

Share this post


Link to post
Share on other sites
What OS is your server?
If its:
- Windows use \r\n
- Linux \n
- Mac \r

Also the same applies with the OS you are viewing the log file in.

Share this post


Link to post
Share on other sites
The newline character is, unfortunately, tied to the OS your server is running on.
"\n" works on UNIX/Linux/VMS
"\r\n" works on Windows

Ken

Share this post


Link to post
Share on other sites
aha.
well php info claims that its a freeBSD machine.  "\r\n" worked, so i dont care either way.  much thanks.

Share this post


Link to post
Share on other sites

×

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.