Solved

Line Breaks in a text file using php

Posted on 2006-11-24
3
205 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
Comment Utility
Try changing it to

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

Author Comment

by:rbosco020475
Comment Utility
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
Comment Utility
No problem its always the simple things that are the most infuriating :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now