Page 1 of 1

how to print php code using PHP File write

Posted: Fri Feb 05, 2010 2:26 pm
by exsillent
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,

Re: how to print php code using PHP File write

Posted: Fri Feb 05, 2010 3:29 pm
by xjake88x
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

Posted: Fri Feb 05, 2010 4:36 pm
by exsillent
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

Posted: Fri Feb 05, 2010 4:45 pm
by xjake88x
And what is the problem that you're having?

Re: how to print php code using PHP File write

Posted: Fri Feb 05, 2010 6:43 pm
by AbraCadaver
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.