tags:

views:

34

answers:

3

Hi, 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 using separate echo's. Can someone tell me how I can accomplish this?

Thanks,

Dennis

+3  A: 

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();
Gumbo
`ob_start(); echo 'foobar'; $contents = ob_get_clean();` - do the same, but it's a little bit more readable.
Crozin
+3  A: 

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.

GSto
A: 

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 />';
Rodolphe