how to print php code using PHP File write

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
exsillent
Forum Newbie
Posts: 2
Joined: Fri Feb 05, 2010 2:17 pm

how to print php code using PHP File write

Post 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,
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Re: how to print php code using PHP File write

Post 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;
}
?>
exsillent
Forum Newbie
Posts: 2
Joined: Fri Feb 05, 2010 2:17 pm

Re: how to print php code using PHP File write

Post 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;
}
?>
User avatar
xjake88x
Forum Commoner
Posts: 50
Joined: Sun Aug 01, 2004 7:05 pm

Re: how to print php code using PHP File write

Post by xjake88x »

And what is the problem that you're having?
User avatar
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

Post 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.
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.
Post Reply