Solved

from echo to file_put_contents

Posted on 2010-11-10
6
420 Views
Last Modified: 2012-05-10
                 echo( implode(" ",$field )
                        . $CSV_separator);

echo to screen


I want to print to file.txt

file_put_contents("file.txt","----answer goes here---------------",FILE_APPEND);
0
Comment
Question by:rgb192
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Amar Bardoliwala
ID: 34101667
Hello rgb192,

I think you can do it as following..

file_put_contents("file.txt", implode(" ",$field ) . $CSV_separator, FILE_APPEND);

Thanks.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34101718
Use the output control.
http://us.php.net/manual/en/ref.outcontrol.php

ob_start();
echo [whatever]
$string = ob_get_contents();
ob_end_clean();

file_put_contents(("file.txt", $string, FILE_APPEND);
0
 

Author Comment

by:rgb192
ID: 34104293
I have many echo statements

would this work


ob_start();
echo [whatever]

..
code
..

echo [whatever]



echo [whatever]

..
code
..

echo [whatever]



$string = ob_get_contents();
ob_end_clean();

file_put_contents(("file.txt", $string, FILE_APPEND);
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rgb192
ID: 34104304
I have many echo statements   and for loops

would this work


ob_start();
echo [whatever]

..
code
..

for loop begin

echo [whatever]

for loop end

echo [whatever]

..
code
..

echo [whatever]



$string = ob_get_contents();
ob_end_clean();

file_put_contents(("file.txt", $string, FILE_APPEND);
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34105410
Of course it will work.  The buffers are stackable.  Just put the ob_start() and ob_get... in the right places.
0
 

Author Closing Comment

by:rgb192
ID: 34110391
thanks
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 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…

830 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