Forum Moderators: coopster
1.helloworld.php
<?
echo "hello world";
?>
2.myhelloworld.php
<?
$myhelloworld = require('/home/chippy/public_html/helloworld.php');
$myfile = @fopen('/home/chippy/public_html/myhelloworld.html', "w");
$fp = fwrite($myfile,$myhelloworld);
fclose($myfile);
?>
I am trying to output the result of the first PHP script to myhelloworld.html but so far it only outputs '1' on that HTML page.
By right, the HTML page should have 'hello world' but that is not happening.
Please help!
Thanks in advance!
1.helloworld.php
<?
function hello() {
return "hello world";
}
?>
<?
require('/home/chippy/public_html/helloworld.php');
$myhelloworld = hello();
$myfile = @fopen('/home/chippy/public_html/myhelloworld.html', "w");
$fp = fwrite($myfile,$myhelloworld);
fclose($myfile);
?>
Or you could play around with output buffering [de3.php.net].
If you use Apache, you could configure PHP to parse html files in addition to php files. Then you simply include/require helloworld.php file in helloworld.html.
I'm not sure what you are trying to accomplish. Maybe there's an easier way ...
This is designed for exactly the situation you describe and should work like a charm.
That said, instead of
echo "<h1>Hello World</h1>";
why don't you write your code as
$html = "<h1>Hello World</h1>";
and then write the $html to a file?
Tom