I have a code that queries db and outputs it in formatted HTML (PHP) via a loop.
I need to extract this code from my current page, put it into a separate script and add a code that will take the output from my query and will save it in a separate file, TXT or any other format, so that i could use that external file as an include.
No, clearly I have the first part -- query my db and output formatted HTML. Now for the second part. I am at a loss at the moment. I was thinking that all I needed to do is write my PHP chunk of code into a function and then create a file like this, but for some reason it just does not work:
function $myHTMLoutput($val, $val2) {
// my php code here
return $string;
}
$saveHTMLexternally = 'more stuff'.$myHTMLoutput($val, $val2);
$filename = '/external.txt';
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, ($saveHTMLexternally)) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
All day and nothing to show forth...