I got this to work with both techniques suggested.
Alexei suggested:
ob_start();
do_something();
print ob_get_clean();
Paul suggested:
would $result = print_r($var, 1); do the trick?
this works:
print print_r(do_something(), true);
I personally favour Alan's suggestion as can run in one line without
interrupting the current output buffer.
However both techniques work perfectly.
This is why I love user groups!
Thanks
Phil
On 25/09/2008, at 2:43 PM, Alexei Tenitski wrote:
>
> ob_start();
> echo "Hello";
> $buffer = ob_get_clean();
>
>
> Philip Arndt wrote:
>> Hi,
>>
>> I'm just wondering if anybody knows of a way to run a function that
>> contains print statements in a mode that will instead "print" to a
>> buffer that I can use inside another function?
>>
>> e.g.
>>
>> function do_something()
>> {
>> print "{success: true}";
>> }
>>
>> but run this like so:
>>
>> function do_something_else
>> {
>> $result = print_to_variable(do_something);
>>
>> print $result . ", {returntype: string}";
>> }
>>
>> Probably a bit of a leftfield request, but that sort of thing is what
>> I'm after.
>>
>> Cheers,
>> Phil
>>
>>>
>
> >
--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---