How to get output of a php function into a variable

It's pretty simple, and it can be very helpfull when for some reason you need to do a conditional display on an output from a function, but for legacy/compatibility reasons you can't modify that function.

  1. <?php
  2.     ob_start();
  3.     echo 'I like cookies';
  4.     $myStr = ob_get_contents();
  5.     ob_end_clean();
  6. ?>
Technology: 

Add new comment