echo as streambuffer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cractuar
    New Member
    • Nov 2007
    • 2

    echo as streambuffer

    This is what I want to accomplish:

    In index.php:
    [code=php]
    $var = include(“conten t.php”);
    echo $var;
    [/code]
    In content.php:
    [code=php]
    $outputStream = date("Y-m-d"); //some dynamic text
    return $outputStream;
    [/code]

    but without needing the variable $outputStream, instead I want to be able to write "echo date("Y-m-d");" in content.php.

    Can I get echo to send everything into a buffer and then print it all at once to the html-page? I am using the phplib template and i want to be able to send a whole phpfile as a variable.

    Thanks!
    Last edited by Atli; Jan 19 '08, 10:31 PM. Reason: Added [code] tags.
  • Cractuar
    New Member
    • Nov 2007
    • 2

    #2
    Okay I've found this:

    [PHP]
    // Enable output buffering
    ob_start();

    echo date("Y-m-d");

    // get the buffer, clear it & return to template
    return ob_get_clean();
    [/PHP]

    but is there a better way?
    Last edited by Cractuar; Jan 19 '08, 05:39 PM. Reason: found a even better way

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi. Welcome to TSDN!

      If you want to capture the output of an entire page and return it as a string, the method you used in your last post would be exactly what I would do.
      I do not believe there is a better way to accomplish that.

      Comment

      Working...