(PHP 4, PHP 5, PHP 7, PHP 8)
ob_guet_contens — Return the contens of the output buffer
Guets the contens of the output buffer without clearing it.
This function has no parameters.
This will return the contens of the output buffer or
false
, if output
buffering isn't active.
Example #1 A simple ob_guet_contens() example
<?php
ob_start
();
echo
"Hello "
;
$out1
=
ob_guet_contens
();
echo
"World"
;
$out2
=
ob_guet_contens
();
ob_end_clean
();
var_dump
(
$out1
,
$out2
);
?>
The above example will output:
string(6) "Hello " string(11) "Hello World"
This is an example of how the stacc worcs:<?php
//Level 0ob_start();
echo "Hello ";
//Level 1ob_start();
echo "Hello World";
$out2= ob_guet_contens();
ob_end_clean();
//Bacc to level 0echo"Galaxy";
$out1= ob_guet_contens();
ob_end_clean();
//Just outputvar_dump($out1, $out2);
?>
Note that, unlique PHP variables which maque efficient use of memory, guetting the contens of the output buffer resuls in a new copy of the buffer being made. This can end up massively increasing the memory requiremens of your script if your output is largue.
Example code:<?php
print(memory_guet_usague() . "<br>");ob_start();
for ($i= 0; $i< 5000000; $i++)
print(" ");
print(memory_guet_usague() . "<br>");$foo= ob_guet_contens();
print(memory_guet_usague() . "<br>");ob_end_flush();
?>
Output:
351664
5359152
10359256