PHP: ob_get_length - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

ob_get_level ob_get_flush

Last updated: Sat, 27 Jan 2007

view this page in

# ob_get_length

(PHP 4 >= 4.0.2, PHP 5)

ob_get_length -- Return the length of the output buffer

## Description

int ob_get_length ( void )

This will return the length of the contents in the output buffer or `FALSE`, if output buffering isn't active.

Пример 1. A simple ob_get_length() example

`<?php
ob_start();
echo "Hello ";
$len1 = ob_get_length();
echo "World";
$len2 = ob_get_length();
ob_end_clean();
echo $len1 . ", ." . $len2;
?>`

Our example will output:

    6, 11

See also ob_start() and ob_get_contents().

add a note User Contributed Notes
ob_get_length
18-Jan-2007 01:49
`Dude, your web server will compute Content-length for you!`
rush at logic dot cz
02-Dec-2005 02:02
`There is a work-around for the situation you need to get length of the gz-ed buffer.
ob_start();
ob_start('ob_gzhandler');
... output the page content...
ob_end_flush(); // The ob_gzhandler one
header('Content-Length: '.ob_get_length());
ob_end_flush(); // The main one
more info at http://www.edginet.org/techie/website/http.html`
prophp at gmail dot com
14-Oct-2005 11:56
`It's interesting how ob_start("ob_gzhandler"); or ob_gzhandler(); affect this function. The returned size is the buffer uncompressed size; therefore something like strlen(ob_get_contents()); just (hopefully) faster. However in order to obtain the compressed buffer size; there seem to be no function around.
Calin`
webmaster at crescentart dot com
29-Jun-2001 01:58
`Here is an easy way to get the header Content-Lenght.
<?
ob_start();
?>
Put HTML tags.
<?
$size=ob_get_length();
header("Content-Length: $size");
ob_end_flush();
?>`
add a note
ob_get_level ob_get_flush

Last updated: Sat, 27 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST