Jump to content


Photo

newline in file writing


  • Please log in to reply
3 replies to this topic

#1 xtoph

xtoph
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 July 2006 - 02:33 PM

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?

fwrite($fh, "hit: ".$ip."     ".$time_date."\n");

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

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 23 July 2006 - 02:40 PM

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.

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 23 July 2006 - 02:40 PM

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

#4 xtoph

xtoph
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 July 2006 - 03:23 PM

aha.
well php info claims that its a freeBSD machine.  "\r\n" worked, so i dont care either way.  much thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users