Solved

from echo to file_put_contents

Posted on 2010-11-10
6
390 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 108

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now