Hi,
I am writing a index.html file using PHP File Write method for example:
$prodout="Lot of Strings and other php variables having information";
$f2 = fopen($fullpath, "w");
fwrite($f2, $prodout);
fclose($f2);
i want to write PHP code so that it shows as php in .html file ( i have setup my server to parse .html pages as php)
for example
$prodout="Lot of Strings and other php variables having information";
$prodout.="<?php include($_SERVER[\"DOCUMENT_ROOT\"].\"/recently-viewed-items.php\"); ?>";
$f2 = fopen($fullpath, "w");
fwrite($f2, $prodout);
fclose($f2);
so when it becomes index.html it will look like
Lot of Strings and other php variables having information
<?php include($_SERVER["DOCUMENT_ROOT"]."/recently-viewed-items.php"); ?>
Any body can help how i can achieve this goal.
Thank you,
how to print php code using PHP File write
Moderator: General Moderators
Re: how to print php code using PHP File write
So what you're trying to do is take the output of a php file and write it into an HTML file?
Code: Select all
<?php
$prodout= get_include_contents('yourFile.php');
$f2 = fopen($fullpath, "w");
fwrite($f2, $prodout);
fclose($f2);
function get_include_contents($filename) {
if (is_file($filename)) {
ob_start();
include $filename;
$contents = ob_get_contents();
ob_end_clean();
return $contents;
}
return false;
}
?>Re: how to print php code using PHP File write
i am not trying to take out put of a php file, instead i am trying to include a php code into html file so when some one access that HTML file that php code compiles
xjake88x wrote:So what you're trying to do is take the output of a php file and write it into an HTML file?
Code: Select all
<?php $prodout= get_include_contents('yourFile.php'); $f2 = fopen($fullpath, "w"); fwrite($f2, $prodout); fclose($f2); function get_include_contents($filename) { if (is_file($filename)) { ob_start(); include $filename; $contents = ob_get_contents(); ob_end_clean(); return $contents; } return false; } ?>
Re: how to print php code using PHP File write
And what is the problem that you're having?
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: how to print php code using PHP File write
You haven't stated the problem, but I can see that it is probably related to this: http://www.php.net/manual/en/language.types.string.php
Read the single and double quotes sections.
Read the single and double quotes sections.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.