Page 1 of 1
How do I convert function output to function return
Posted: Wed Aug 17, 2005 5:56 pm
by Luke
I don't really know how to word this... I have a function that just dumps information to the browser. I remember reading something on php.net about a function that can take output and put it in a variable. I can't find it ANYWHERE now. anybody know what it is??
Code: Select all
logerror("Could not post event: ".getdetails($_SESSION));
getdetails is a function that just dumps information about a variable onto the browser. How do I take that information and put it in a variable so I can save it into a log?
Posted: Wed Aug 17, 2005 5:57 pm
by feyd
output buffering..
ob_start() will get you where you want.
Posted: Wed Aug 17, 2005 6:09 pm
by Luke
I remember there was some function that did this:
Code: Select all
$variable = whateverthefunctionwas(print("Text text text"));
Does anybody know what it is?
Posted: Wed Aug 17, 2005 6:11 pm
by feyd
I just told you, and was kind enough to give you a link to it.
Posted: Wed Aug 17, 2005 6:19 pm
by Luke
I know. I appreciate it very much. Thanks. But it's not what I'm looking for. The function I found was much simpler that that.
Posted: Wed Aug 17, 2005 6:21 pm
by feyd
there is none, last I saw that does "exactly" what you wrote in your previous example. Besides, the code you posted would send the result (1) to the function in question... why not add some functionality to your getdetails() function that you can tell it to return the string or echo it, it shouldn't be that complicated..
Posted: Wed Aug 17, 2005 6:21 pm
by timvw
All i can think of is: (Just add
http://www.php.net/ before the name of the functions to look them up..)
ob_get_contents
print_r
eval
Posted: Wed Aug 17, 2005 7:22 pm
by RobertGonzalez
In your function code, getdetails(), take the information that is being echo'ed and assign that data to a variable. For example:
Code: Select all
function getdetails($some_data)
{
$return_data = '';
if (is_array($some_data)
{
foreach($some_data as $data_value)
{
$return_data .= $data_value . '<br />';
}
}
return $return_data;
}
Is this what you are looking for? Using this you could easily write to the HTML the value of the information returned from what was passed to your function.
Hope I read your question correctly.