Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Line Breaks in a text file using php

Posted on 2006-11-24
3
Medium Priority
?
213 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 1000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

721 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