March 26, 2012

How to get the rendered PHP+HTML codes into a text file?

Question by Leo Chan

I have a file which is combination of PHP and HTML.

How can i get the plain HTML code output from this file into a text file? or either put it into the text box.

The code of my form, which i use to generate an HTML form can be found here

Answer by Starx

Update:

It seems OP is asking about HOW to get the rendered PHP+HTML codes into a text file?

//get the output from the file
ob_start();
include "yourphpplushtml.php";
$output = ob_get_clean();

//now create a text file and write to it
$fp = fopen('data.txt', 'w+');
fwrite($fp, $output); //put the output
fclose($fp); //close the handler

//Or put it into the textare

echo '<textarea>'.$output.'</textarea>';

Previous Answer But may be helpful to others too

There are many ways HTML can be combined with PHP

  1. Output HTML directly from PHP

    <?php
       echo "<head><title>my new title</title></head>";
    ?>
    
  2. Include PHP inside you HTML

    <title><?php echo $dynamictitle; ?></title>
    
  3. Or even separate them in old fashioned complicated way

    <?php if($resultFound == true) { ?>
        <p> The result was successfully found.</p>
    <?php } ?>
    

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!