PHP Doku:: Get current buffer contents and delete current output buffer - function.ob-get-clean.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDas Verhalten von PHP beeinflussenAusgabepufferungOutput-Control-Funktionenob_get_clean

Ein Service von Reinhard Neidl - Webprogrammierung.

Output-Control-Funktionen

<<ob_flush

ob_get_contents>>

ob_get_clean

(PHP 4 >= 4.3.0, PHP 5)

ob_get_cleanGet current buffer contents and delete current output buffer

Beschreibung

string ob_get_clean ( void )

Gets the current buffer contents and delete current output buffer.

ob_get_clean() essentially executes both ob_get_contents() and ob_end_clean().

Rückgabewerte

Returns the contents of the output buffer and end output buffering. If output buffering isn't active then FALSE is returned.

Beispiele

Beispiel #1 A simple ob_get_clean() example

<?php

ob_start
();

echo 
"Hello World";

$out ob_get_clean();
$out strtolower($out);

var_dump($out);
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:


string(11) "hello world"

Siehe auch


5 BenutzerBeiträge:
- Beiträge aktualisieren...
56ka dot prog at gmail dot com
14.09.2010 2:27
Hi

Warning, this command isn't exactly like ob_get_contents() and ob_end_clean() successively. Sometimes you will have to do these two commands manually.

Today I lost 2 hours to localize that problem and to find the solution -_-'

See you
profix at cms-studio dot net
10.07.2008 4:01
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
egbert teeselink
2.02.2008 16: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.08.2005 16:10
Notice that the function beneath does not catch errors, so throw in an @ before those ob_* calls
webmaster at ragnarokonline dot de
2.10.2003 2: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;
    }
}
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)