Get echo data in a variable?

hi,

I am trying to find , is there any way we can convert an echo data to a variable.

like .

echo ‘test’;

$test=somehow(echo ‘test’);

because then I can use the $test variable as I want in my project…

Output buffering is your friend!


ob_start();
echo "Hello, world!";
$test = ob_get_clean();

echo $test;