Maybe it can be useful
$__ob_stack=array();
function ob_break() {
global $__ob_stack;
while (ob_get_level()>0)
array_push($__ob_stack,ob_get_clean());
}
function ob_continue() {
global $__ob_stack;
while (count($__ob_stack)>0) {
ob_start();
echo array_pop($__ob_stack);
}
}
ob_start();
echo "1"; // now we write to "ob" buffer
ob_break();
echo "2"; // now we write to stdout
ob_continue();
echo "3"; // now we write again to "ob" buffer
$output=ob_get_clean();
echo $output;
// output is 213
ob_get_clean
(PHP 4 >= 4.3.0, PHP 5)
ob_get_clean — 현재 버퍼 내용을 얻은 뒤에 현재 출력 버퍼를 지웁니다.
설명
string ob_get_clean
( void
)
출력 버퍼의 내용을 반환하고 출력 버퍼링을 종료합니다. 출력 버퍼링이 존재하지 않으면 FALSE를 반환합니다. ob_get_clean()은 ob_get_contents()와 ob_end_clean()을 실행한 것과 동일합니다.
Example#1 간단한 ob_get_clean() 예제
<?php
ob_start();
echo "Hello World";
$out = ob_get_clean();
$out = strtolower($out);
var_dump($out);
?>
이 예제의 출력은:
string(11) "hello world"
참고: ob_start(), ob_get_contents().
ob_get_clean
profix at cms-studio dot net
09-Jul-2008 07:01
09-Jul-2008 07:01
egbert teeselink
02-Feb-2008 07:47
02-Feb-2008 07:47
If you're trying to capture the output from an included 3rd party script you don't seem to be capturing everything, the following might help:
function ob_end_clean_all()
{
$s = "";
do
{
$s = ob_get_contents() . $s;
} while(ob_end_clean());
return $s;
}
This function closes all nested output bufferings, therefore closing any buffers that the included script does not explicitly close. It's basically a ob_end_clean that sweeps together all the output buffers instead of just the innermost one.
ludvig dot ericson at gmail dot com
10-Aug-2005 07:10
10-Aug-2005 07:10
Notice that the function beneath does not catch errors, so throw in an @ before those ob_* calls
webmaster at ragnarokonline dot de
01-Oct-2003 05:21
01-Oct-2003 05:21
Running PHP4 < 4.3.0, you can simply add the following to use the function anyway:
<?php
if (!function_exists("ob_get_clean")) {
function ob_get_clean() {
$ob_contents = ob_get_contents();
ob_end_clean();
return $ob_contents;
}
}
?>
