PHP ob_get_contents() Function Last Updated : 18 Sep, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The ob_get_contents() is an inbuilt function in PHP that is used to capture what is currently being buffered by the output buffer. This function returns the output buffer. Syntaxob_get_contents(): string | falseParameter This function does not accept any parameters. Return Value The ob_get_contents() function in PHP returns the contents of the output buffer as a string. If this function does not return any content buffer then it will return false. Program 1: The following program demonstrates the ob_get_contents() Function. PHP <?php ob_start(); echo "This is some text in the output buffer."; $bufferContents = ob_get_contents(); ob_end_clean(); // Output the stored contents echo "Contents of the output buffer: " . $bufferContents; ?> Output: Contents of the output buffer: This is some text in the output buffer. Program 2: The following program demonstrates the ob_get_contents() Function. PHP <?php ob_start(); echo "Today's date is: " . date("Y-m-d"); $bufferContents = ob_get_contents(); ob_end_clean(); $modifiedContents = str_replace("date", "time", $bufferContents); echo $modifiedContents; ?> Output: Today's time is: 2023-07-25 Program 3: The following program demonstrates the ob_get_contents() function. PHP <?php ob_start(); // Generate some output in a loop for ($i = 1; $i <= 5; $i++) { echo "Line $i: GEEKS for GEEKS .<br>"; } $bufferContents = ob_get_contents(); ob_end_clean(); // Modify the captured contents $modifiedContents = strtoupper($bufferContents); // Output the modified contents echo $modifiedContents; ?> Output: Reference: https://www.php.net/manual/en/function.ob-get-contents.php Comment More infoAdvertise with us Next Article PHP ob_get_level() Function N neeraj3304 Follow Improve Article Tags : PHP 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 file_get_contents() Function In this article, we will see how to read the entire file into a string using the file_get_contents() function, along with understanding their implementation through the example.The file_get_contents() function in PHP is an inbuilt function that is used to read a file into a string. The function uses 3 min read PHP | mime_content_type() function The mime_content_type() function is an inbuilt function in PHP which is used to get the MIME content-type of a file. Syntax: string mime_content_type( $file ) Parameters: This function accepts single parameter $file which specifies the path of the file which MIME details to be find. Return Value: Th 1 min read PHP | file_put_contents() Function The file_put_contents() function in PHP is an inbuilt function which is used to write a string to a file. The file_put_contents() function checks for the file in which the user wants to write and if the file doesn't exist, it creates a new file. The path of the file on which the user wants to write 2 min read PHP ob_get_level() Function 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 f 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 Like