YamdaBlam!

Capturing echo output and storing it in a variable

by on Jul.06, 2011, under PHP

Working with legacy code somethings throws up little eggs that need to be cracked.
For instance, I need to use a function which is generally called via the browser and instead of using return statements, it uses echo.

This post shows you how to deal assign echo statements into a local variable by using output control.

ob_start();
helloWorld(param1, param2);
$capturedVar = ob_get_contents();
ob_end_clean();

The echo from the function helloWorld() is now stored in $capturedVar for use!

:, , , ,
No comments for this entry yet...

Leave a Reply

Powered by WP Hashcash

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!