PHP ob_get_length() Function
Last Updated :
24 Apr, 2025
The ob_get_length() function is an inbuilt function in PHP that is used to get the length of the current output buffer. The output buffer length is the number of bytes in the buffer.
Syntax:
ob_get_length(): int|false
Parameters: This function does not accept any parameter.
Return Values: The ob_get_length() function returns the length of the current output buffer in bytes as an integer. If the output buffering is not active or if there is no content in the buffer then it will return "false".
Program 1: The following program demonstrates the ob_get_length() function.
PHP
<?php
// Start output buffering
ob_start();
echo "This is content inside the buffer.";
$bufferLength = ob_get_length();
echo "Buffer length: " . $bufferLength . " bytes.";
ob_end_flush();
?>