Skip to main content

Posts

Showing posts from November 6, 2011

Capturing echo Output into a Variable in PHP

Hi Guys, This is cool stuff. Did you ever know that you can capture the echo output in your PHP code? Since the echo function is void (which means returns nothing) you might have thought that is not possible on this Earth right? I thought that too. But guess what, this as easy as 4 lines.. :O Code:    ob_start();    echo 'Hello World!';    $hello_str   = ob_get_contents();    ob_end_clean(); That will store your "Hello World!" string into the $hello_str variable without actually echoing it on the browser. Give it a try fellas! ;-) Cheers.