What is the easiest way to suppress any output, can a function be generated? Say I have it:
function testFunc () {echo 'test'; Back true; }
And I want to call testFunc () and want to get the return value without displaying the "test" in the page. Suppose it will be in the context of other codes that does produce other things, is there a good way to do this? Probably mess with the output buffer?
Yes, the mess is exactly the answer. Just turn it on before calling your method which will be output (Not only the function, but where you call it, you can wrap it around your entire script or script, but you can make it as "tight" as possible by wrapping it around the call of the method):
function foo () {echo "flush!"; Back true; } Ob_start (); $ A = foo (); Ob_end_clean ();
No more output has been generated.
Comments
Post a Comment