Solved

Line Breaks in a text file using php

Posted on 2006-11-24
3
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

623 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