I'm working with some functions that echo
output. But I need their return
so I can use them in PHP.
This works (seemingly without a hitch) but I wonder, is there a better way?
function getEcho( $function ) {
$getEcho = '';
ob_start();
$function;
$getEcho = ob_get_clean();
return $getEcho;
}
Example:
//some echo function
function myEcho() {
echo '1';
}
//use getEcho to store echo as variable
$myvar = getEcho(myEcho()); // '1'
echo return_echo(myEcho());
takes roughly 5x as long asmyEcho();
– Nickerson