Capturing echo into a variable - using output buffering

by Rekha 2011-01-04 17:11:27

Capturing echo into a variable - using output buffering



In a case where a function echo's some value instead of returning value and if you have to assign the value to a php or javascript variable,

you have to use output buffering concept.

For example,

function test()
{
echo "Welcome";
}



test(); - will echo "Welcome". If you want to store the value and use it for some other purpose,

use the following,

ob_start();
test();
$output = ob_get_clean();
print $output;


Tagged in:

1314
like
0
dislike
0
mail
flag

You must LOGIN to add comments