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.
Output Buffering Control
- 소개
- 설치/설정
- 예약 상수
- 예제
- Output Control 함수 목록
- flush — 출력 버퍼를 비웁니다
- ob_clean — 출력 버퍼를 지웁니다
- ob_end_clean — 출력 버퍼를 지우고 출력 버퍼링을 종료
- ob_end_flush — 출력 버퍼를 전송하고 출력 버퍼링을 종료
- ob_flush — 출력 버퍼를 전송합니다
- ob_get_clean — 현재 버퍼 내용을 얻고 현재 출력 버퍼를 삭제
- ob_get_contents — 출력 버퍼의 내용을 반환
- ob_get_flush — Flush the output buffer, return it as a string and turn off output buffering
- ob_get_length — 출력 버퍼의 길이를 반환
- ob_get_level — 출력 버퍼링 메커니즘의 중첩 단계를 반환
- ob_get_status — 출력 버퍼의 상태를 얻습니다
- ob_gzhandler — gzip 출력 버퍼를 위한 ob_start 콜백 함수
- ob_implicit_flush — 즉시 출력의 여부를 결정
- ob_list_handlers — List all output handlers in use
- ob_start — 출력 버퍼링을 켭니다
- output_add_rewrite_var — Add URL rewriter values
- output_reset_rewrite_vars — Reset URL rewriter values
clancy hood at gmail dot com
11-Apr-2009 11:33
