PHP ob_get_contents() function

The ob_get_contents() function is used to return the content of the output buffer. This is used before buffer clean and after output start.

Syntax

ob_get_contents( void ) : string

This function returns buffered data or FALSE, if output buffering is not active.



Example

<?php
    ob_start();
    echo $var = "Hello john";
    $data1 = ob_get_contents();
	
    echo $var1 = " How are you?";
    $data2 = ob_get_contents();
	
    ob_end_clean();
    var_dump($data1, $data2);
?>

Output -

string(10) "Hello john" string(23) "Hello john How are you?"



Related PHP Functions

PHP array_reverse() function
PHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function




Read more articles


General Knowledge



Learn Popular Language