Re: About printing functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/1/21 Thodoris <tgol@xxxxxxxxxx>

>
>
>> On Jan 21, 2009, at 1:33 PM, Thodoris wrote:
>>
>>  Hi gang,
>>>   Lets say that you have a function that prints something to the output
>>> simply like this:
>>>
>>> function print_str() {
>>>   print "blah blah blah";
>>> }
>>>
>>> I was wondering if there is a way to use this output and store it in a
>>> var or something without changing the function itself?
>>> And store the "blah blah blah" somewhere for later use?
>>>
>>> I can think of many reasons that someone could use this.
>>>
>>>
>> I know you said without changing the function... but is there any reason
>> that you can't simply add this:
>>
>> <?PHP
>> function print_str() {
>>    $str = "blah blah blah";
>>    print $str;
>> }
>> ?>
>>
>> Totally untested and just trying to understand why :)
>>
>>
>> --
>> Jason Pruim
>> japruim@xxxxxxxxxx
>> 616.399.2355
>>
>>
>>
>>
>>
> Well Jason my point is theoretical. Lets just say that this function
> doesn't just print "blah blah blah" but like tones of html that you may like
> to reuse...
>

> Well you could always change it to this:
>
> function print_str() {
>   $str = "blah blah blah";
>   return $str;
> }
>
> and use the output you got from the function whenever you like (print it,
> make it a toast, cook it with bees etc).
>
> But the question still remains: Is there a way to do this?
>
>
> --
> Thodoris
>

IMO it is always better to return strings than directly printing. there
would be no problem even if it would contain tones of html...

but what comes in my mind is output_buffering...
see: http://de3.php.net/manual/en/book.outcontrol.php

-eddy

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux