PHP ob_get_length() Function

❮ PHP Output Control Functions

Example

Display the number of characters in the output buffer:

<?php
ob_start();
echo "Hello World!";
$length = ob_get_length();
ob_end_clean();

echo "The contents of the buffer are $length characters long";
?>
Try it Yourself »

Definition and Usage

The ob_get_length() function returns the length of the topmost output buffer's contents in bytes. This is not always the same as the number of characters because some characters may have more than one byte.


Syntax

ob_get_length();

Technical Details

Return Value: Returns an integer indicating how many bytes are in the output buffer
PHP Version: 4.0.2+

❮ PHP Output Control Functions
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.