PHP ob_get_contents() Function Last Updated : 18 Sep, 2023 Comments Improve Suggest changes 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_clean() 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 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 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 | 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 | 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 Like