smidgen11 Posted December 5, 2011 Share Posted December 5, 2011 Hi, I am trying write the contents of a php file's output, which echos out a small output of text based on variables and calulations, to a single file. I have tried fwrite and file_get_contents. When I run my code I get the file to create but the file it creates only outputs "1". Here is a look at my code: fwrite version: $text= include '$Site-2851.php'; $file = fopen("myfile.txt","w"); echo fwrite($file, $text); fclose($file); file_get_contents version: $text= include '$Site-2851.php'; $file = 'myfile.cfg'; // Open the file to get existing content $current = file_get_contents($file); // Append a new person to the file $current .= $text; // Write the contents back to the file file_put_contents($file, $current); Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/252510-fwrite-or-file_get_contents-help/ Share on other sites More sharing options...
kicken Posted December 5, 2011 Share Posted December 5, 2011 include() returns true or false depending on whether the include was a success or not. If you file contains a 'return' statement it will return that instead. If you file just contains a bunch of echo's though and you want to capture that, you need to use output buffering. ob_start(); include 'file.php'; $output = ob_get_clean(); //write $output to file Quote Link to comment https://forums.phpfreaks.com/topic/252510-fwrite-or-file_get_contents-help/#findComment-1294647 Share on other sites More sharing options...
smidgen11 Posted December 5, 2011 Author Share Posted December 5, 2011 Thanks a lot. That did it. Quote Link to comment https://forums.phpfreaks.com/topic/252510-fwrite-or-file_get_contents-help/#findComment-1294654 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.