How to store all in a variable instead of echoing everything separately?
please see: http://pastebin.com/5za3uCi1
I'm quite new to php and I'm editing the ventrilo status script. What I'd like it to do is that it stores everything in one big variable for easy parsing instead of 开发者_如何学Pythonusing separate echo's. Can someone tell me how I can accomplish this?
Thanks,
Dennis
You can use the output buffer and get the contents of it:
ob_start();
echo 'foobar';
$contents = ob_get_contents(); // now contains 'foobar'
ob_end_clean();
declare a variable at the beginning, say $data or whatever. then, replace the echo calls:
echo "hello";
with this:
$data .= "hello";
then return the $data variable at the end of the function.
Instead of the echo, you can use a simple affectation :
$request = "CVentriloStatus->Request() failed. <strong>$stat->m_error</strong><br><br>\n";
But you'll soon have issues to manage multiple variables.
You could create an object to handle and store your information, but If you need something easy to set up and simple to operable, I'd go for arrays :
$ventriloStatus = array();
$ventriloStatus['requestObj'] = $stat->Request();
$ventriloStatus['requestMsg'] = "CVentriloStatus->Request() failed. <strong>$stat->m_error</strong><br><br>\n";
Add your data using keys. Then retrieve the value easily :
echo $ventriloStatus['requestMsg'];
You can even parse your data using a simple loop
foreach($ventriloStatus as $key => $value){
echo $key.' : '.$value.'<br />';
精彩评论