By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,049 Members | 1,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,049 IT Pros & Developers. It's quick & easy.

How to store the output as textfile

P: 34
Hi
i wanna help..While php script running in browsers,the output must stored as text file simultaneously.
i dont know how to do..
can anyone provide me a solution....
Feb 9 '07 #1
Share this Question
Share on Google+
2 Replies


P: 99
I think the simplest solution is to define a variable to catch the output to and if it's done write it to the textfile.

[PHP]
$textcontent = '';
for($i=0;$i<10;$i++){
// regular output
echo $i.'<br>';
// catching for file
$textcontent .= $i.chr(10);
}
// php.net code ;)
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $textcontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($textcontent) to file ($filename)";

fclose($handle);
[/PHP]

it's not simultanious but it's very close.
Feb 9 '07 #2

stephane
P: 35
Hi
i wanna help..While php script running in browsers,the output must stored as text file simultaneously.
i dont know how to do..
can anyone provide me a solution....
to store all output to variable you can use ob_ php fucntions
var value, you can store at file at server or print to screen.
Feb 9 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.