PHP ob_get_level() Function Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The ob_get_level() function is an inbuilt function in PHP that is used to get the current output buffer level in a nested level. Output buffering is a feature in PHP that allows you to capture and manipulate output before it is sent to the browser or client. Syntaxob_get_level(): intParameter This function does not accept any parameters. Return Values The ob_get_level() function returns an integer value that represents the current value of the output buffering. Program 1: The following program demonstrates the ob_get_level() Function. PHP <?php ob_start(); $bufferingLevel = ob_get_level(); // Output some content echo "This is content inside the buffer."; // Start a new output buffer ob_start(); // Get the new output buffering level $bufferingLevelNew = ob_get_level(); // Output more content inside the new buffer echo "This is content inside the new buffer."; // End the new buffer ob_end_flush(); // Check the output buffering level // after ending the new buffer $bufferingLevelAfterEnd = ob_get_level(); // End the original buffer ob_end_flush(); ?> Output: This is content inside the buffer.This is content inside the new buffer. Program 2: The following program demonstrates the ob_get_level() Function. PHP <?php // Start output buffering ob_start(); // Function to check output buffering level // and perform actions accordingly function checkOutputBufferLevel() { $bufferingLevel = ob_get_level(); // Display the output buffering level echo "Output buffering level: " . $bufferingLevel . "<br>"; // Perform actions based on the output buffering level if ($bufferingLevel === 1) { echo "You are in the top-level buffer.<br>"; } elseif ($bufferingLevel > 1) { echo "You are in a nested buffer.<br>"; } else { echo "Output buffering is not active.<br>"; } } checkOutputBufferLevel(); echo "This is content inside the buffer.<br>"; ob_end_flush(); ?> Output: Output buffering level: 1 You are in the top-level buffer. This is content inside the buffer. Reference: https://www.php.net/manual/en/function.ob-get-level.php Comment More infoAdvertise with us Next Article PHP ob_get_clean() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-output PHP-function Similar Reads PHP ob_get_clean() Function The ob_get_clean() function is an in-built PHP function that is used to clean or delete the current output buffer. It's also used to get the output buffering again after cleaning the buffer. The ob_get_clean() function is the combination of both ob_get_contents() and ob_end_clean(). Syntax: string|f 2 min read PHP gettype() Function The PHP gettype() function returns the type of a variable as a string. It identifies the variable's data type, such as string, integer, array, boolean, etc., allowing developers to check and handle different data types dynamically.Syntax:string gettype ( $var )Parameter: This function accepts a sing 2 min read PHP ob_get_status() Function The ob_get_status() is an inbuilt function in PHP that is used for retrieving the status of the output buffer. Syntaxob_get_status(bool $full_status = false) : arrayParameter This function accepts only one parameter which is described below. $full_status: This is an optional parameter. If this param 2 min read PHP | getservbyname() Function The getservbyname() function is an inbuilt function in PHP which returns the port number for given protocol and Internet service. Syntax: int getservbyname( string $service, string $protocol ) Parameters: This function accepts two parameters as mentioned above and described below: $protocol: It is r 2 min read PHP | getservbyport() Function The getservbyport() function is an inbuilt function in PHP which returns the Internet service for given protocol and port number. Syntax: string getservbyport( int $port, string $protocol) Parameters: This function accepts two parameters as mentioned above and described below: $protocol: It is requi 1 min read PHP getrusage() Function The getrusage() function is an inbuilt function in PHP that returns current resource usage. Syntax: getrusage(int $mode = 0)Parameters: This function has only one parameter: $mode: This parameter will be called with RUSAGE_CHILDREN, if the mode will be 1.Return Value: This function returns an assoc 1 min read Like