Solved

from echo to file_put_contents

Posted on 2010-11-10
6
435 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
[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
  • 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 110

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
Revamp Your Training Process

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

 

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 110

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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

632 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