www.webdeveloper.com
Results 1 to 2 of 2

Thread: Output buffering

  1. #1
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    232

    Output buffering

    I'm trying to use php's output buffering functions. But I haven't really succeeded yet. I have a txt-file with the contents:

    test.txt:
    <font color="#FF0000"><b>$var</b></font>

    I'm trying to capture what's in here then assign a value to $var and print it. This is my code so far.

    test.php:
    <?php
    $var = "It works!";
    ob_start ();
    include ('test.txt');
    $test = ob_get_contents ();
    ob_clean ();
    ob_end_flush ();

    echo "$test";
    ?>

    It prints out (viewing source code):
    <font color="#FF0000"><b>$var</b></font>

    So the variable $var hasn't gotten his value.

    Thanks in advance.

  2. #2
    Join Date
    Nov 2003
    Location
    Aachen, Germany
    Posts
    4,090
    Hi!

    There is no php in your test.txt, so $var is just a string.

    This works:
    test.txt:
    PHP Code:
    <?PHP
    echo "<font color=\"#FF0000\"><b>$var</b></font>";
    ?>
    test.php:
    PHP Code:
    <?php 
    $var 
    "It works!"
    include (
    'test.txt'); 
    ob_start (); 
    $test ob_get_contents (); 
    ob_clean (); 
    ob_end_flush (); 
    echo 
    $test
    ?>
    Cheers - Pit

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles