I have a PHP file called test.php that contains the following code.
<?php
$text = 'Grrrrr';
ob_start();
require_once('testinc.php');
$html2 = ob_get_clean();
echo '<pre>';
var_dump($html2);
echo '</pre>';
$text = 'wtf';
ob_start();
require_once('testinc.php');
$html2 = ob_get_clean();
echo '<pre>';
var_dump($html2);
echo '</pre>';
testing('blah');
testing('123');
function testing($text) {
ob_start();
require_once('testinc.php');
$html = ob_get_clean();
echo '<pre>';
var_dump($html);
echo '</pre>';
}
The testinc.php file contains the following code.
<?php
echo $text;
?>
testing
When I run the code, the output looks like this.
string(13) "Grrrrrtesting"
string(0) ""
string(0) ""
string(0) ""
Why is the buffer not working other than the first time and how can I get the output to look like this?
string(13) "Grrrrrtesting"
string(10) "wtftesting"
string(11) "blahtesting"
string(10) "123testing"