PHP: eval() without output to screen

Sometimes, we need to eval() some lines of code and grab the result without output to screen. As you know, eval() has only one parameter, so we have to use output buffer for that purpose. The following code can achieve that. Pretty clean and understandable:

ob_start();
eval('echo "Hello world!";');
$str = ob_get_contents();
ob_end_clean();

$str will hold the output returned by eval function.