[Webinar] Streamline your web hosting managementRegister Today


php echo to txt file noy screen

Posted on 2011-10-08
Medium Priority
Last Modified: 2012-05-12
I have a process thar loops and sends a line to the screen:

 echo $output;

It creates a page withh all the strings that are echoed

I need to create a.txt file that will have the same lines of the screen.

That is create a txt file and then append succesive data strings to it

So I need to crete a txt file
Append lines of text to it
Close the file

I can do this in asp quite simpel but I am new to php

Question by:robrodp
  • 3
  • 2
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 36936140
At it's most basic here is an example. Easy to wrap in a useful function.

$log = file_get_contents(logtextfile);
$log .= '\l\n'.'new stuff to log'


Author Comment

ID: 36936219
I prepared and ran this:

$log = file_get_contents('test.txt');
$log .= '\l\n'.'new stuff to log'

I get this error:

Parse error: syntax error, unexpected T_STRING in C:\Inetpub\vhosts\antologiadelabelleza.com\httpdocs\entelsa\test.php on line 4
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 36936225
; on middle line
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

ID: 36936233
Getting there.

Warning: file_put_contents() expects at least 2 parameters, 1 given in C:\Inetpub\vhosts\antologiadelabelleza.com\httpdocs\entelsa\test.php on line 4

Accepted Solution

amigura earned 2000 total points
ID: 36936362
you forgot filename in put

but you could use this without $log = file_get_contents('test.txt');

$log = "\nnew stuff to log";
file_put_contents('test.txt', $log, FILE_APPEND);

Open in new window


Author Closing Comment

ID: 36936370
Fast and to the point thx

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
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…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

590 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