cryptinitedemon Posted June 5, 2008 Share Posted June 5, 2008 Is there anyway that I can take the output of echo and put it in a string variable? The reason I ask is because I'm using some stupid pre-built web program and it will echo out the variable value just fine. But internally to get this variable there are some 20-something different functions that return this value up a hierarchy. And whenever I pass this variable to anything to compare it to some string, it can't do crap with it. I really don't have the time to search through all these nested calls to see how the programmer formatted it. Link to comment https://forums.phpfreaks.com/topic/108843-echo-into-a-variable/ Share on other sites More sharing options...
flyhoney Posted June 5, 2008 Share Posted June 5, 2008 I would take a look at this: http://us.php.net/ob_start From the documentation: <?php function callback($buffer) { // replace all the apples with oranges return (str_replace("apples", "oranges", $buffer)); } ob_start("callback"); ?> <html> <body> <p>It's like comparing apples to oranges.</p> </body> </html> <?php ob_end_flush(); ?> The above example will output: <html> <body> <p>It's like comparing oranges to oranges.</p> </body> </html> Link to comment https://forums.phpfreaks.com/topic/108843-echo-into-a-variable/#findComment-558324 Share on other sites More sharing options...
flyhoney Posted June 5, 2008 Share Posted June 5, 2008 ob_start(); echo 'stuff' $buffer = ob_get_contents(); ob_end_clean(); And then $buffer will contain all the echo'ed stuff. Link to comment https://forums.phpfreaks.com/topic/108843-echo-into-a-variable/#findComment-558327 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.