The manual is a little shy on explaining that output buffers are nested, and that "turns off output buffering" means turning off the highest nested buffer. See ob_get_level (for a useful function, but still no explanation)
<?php
ob_start();
echo "1:blah\n";
ob_start();
echo "2:blah";
// ob_get_clean() returns the contents of the last buffer opened. The first "blah" and the output of var_dump are flushed from the top buffer on exit
var_dump(ob_get_clean());
exit;
?>
puts:
1:blah
string(6) "2:blah"
Prior to realising this, I had thought PHP's ob functionality left more to be desired. I *really* wish I knew earlier.
Ausgabepufferung
- Einführung
- Installation/Konfiguration
- Vordefinierte Konstanten
- Beispiele
- Output-Control-Funktionen
- flush — Leert (sendet) den Ausgabepuffer
- ob_clean — Löscht den Ausgabepuffer
- ob_end_clean — Löscht den Ausgabe-Puffer und deaktiviert die Ausgabe-Pufferung
- ob_end_flush — Leert (schickt/sendet) den Ausgabe-Puffer und deaktiviert die Ausgabe-Pufferung
- ob_flush — Leert (sendet) den Ausgabepuffer
- ob_get_clean — Get current buffer contents and delete current output buffer
- ob_get_contents — Gibt den Inhalt des Ausgabe-Puffers zurück
- ob_get_flush — Flush the output buffer, return it as a string and turn off output buffering
- ob_get_length — Return the length of the output buffer
- ob_get_level — Anzahl der aktiven Ausgabepuffer
- ob_get_status — Get status of output buffers
- ob_gzhandler — ob_start callback function to gzip output buffer
- ob_implicit_flush — Schaltet die implizite Ausgabe ein bzw. aus
- ob_list_handlers — List all output handlers in use
- ob_start — Ausgabepufferung aktivieren
- output_add_rewrite_var — Setzt URL Revriter Variablen
- output_reset_rewrite_vars — Reset URL rewriter values
Ausgabekontrolle
clancy hood at gmail dot com
11-Apr-2009 06:33
11-Apr-2009 06:33
