Solved

Line Breaks in a text file using php

Posted on 2006-11-24
3
206 Views
Last Modified: 2008-02-20
I have a log file that I am writing to using php when certain events happen on my web site project. I can open the file, write the entry, and close it ok, but I cannot seem to figure out how to format the text file so that each entry is on a single line in the document.

The code I am using is:

$fp = fopen("./logfiles/insert_log.txt", "a+");
if (!$fp) die ("Cannot open database transaction log");

fwrite($fp, "$subdate|$id|$userid|New record created|success ");
fclose($fp);

The result is:

11/24/2006 00:00:00.000|1001|New record created|success 11/24/2006 00:00:00.000|1001|New record created|success 11/24/2006 00:00:00.000|1001|New record created|success



Anyone know how I can make the result look like this format:   (One line per insert to the file.)

11/24/2006 00:00:00.000|1001|New record created|success
11/24/2006 00:00:00.000|1001|New record created|success
11/24/2006 00:00:00.000|1001|New record created|success



Thanks

0
Comment
Question by:rbosco020475
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
rhickmott earned 250 total points
ID: 18008413
Try changing it to

fwrite($fp, "$subdate|$id|$userid|New record created|success\n");
0
 

Author Comment

by:rbosco020475
ID: 18008509
That worked! Something so simple that everyone that I asked so far could not offer as a suggestion. Thanks.
0
 
LVL 13

Expert Comment

by:rhickmott
ID: 18008512
No problem its always the simple things that are the most infuriating :)
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question