I've got a script i wrote that is piecing together a CSV. Part of this task is to include HTML code inside of the CSV. What i'm trying to do is save the output of a file like text_file.php to a variable like $text_file_output. I can't figure out a way to include the output of a PHP page to a variable.

Any help is appreciated!

    output buffering is the easiest option.

    <?php
      ob_start();
    
      // script goes here.
    
      $text_file_output = ob_get_contents();
      ob_end_flush();
    ?>
    
      thorpe wrote:

      output buffering is the easiest option.

      <?php
        ob_start();
      
        // script goes here.
      
        $text_file_output = ob_get_contents();
        ob_end_flush();
      ?>
      

      That sorta works.. Although the ob_end_flush returned all results back to the calling script so i got a 7mb php file 😉. This is what i used, but it's still giving some odd results on the calling page.

      		ob_start();
      		require('html_template.php');
      		$html_template = ob_get_contents();
      		ob_end_clean();

        if you want to get the output of a php script from within another php script (not from within itself) use...

        <?php
        
          $html_template = file_get_contents('html_template.php');
        
        ?>
        

          Ok actually both work for me now thorpe. I originally had some funky stuff that screwed up the output buffering.

          Thanks a lot for your help. 😃

            Write a Reply...