By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

PHP 5.0.0RC3 output buffering bug?

P: n/a
A question about Output Buffering in PHP-CLI.

Is it expected that the following code will emit two representations of $x?

I would like to use print_r(), but capature its output in a String, to use
ain a generic logging infrastructure. But every call to print_r(),
var_dump(), var_export(), et. al. goes to STDOUT no matter what I do?

How to I get print_r() to return a string, and not go to STDOUT?

Platform: php-5.0.0RC3 CLI configured/compiled/installed via FreeBSD 5.2.1 ports.
<?php

$x = array('this', 'that', 'the other thing');

ob_start();
print_r($x);
$result = ob_get_flush();

print "$result\n";

?>

--
Mark Evenson <ev*****@panix.com>

"A screaming comes across the sky. It has happened before, but there is
nothing to compare to it now."
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Mark Evenson wrote:
A question about Output Buffering in PHP-CLI.

Is it expected that the following code will emit two representations
of $x?

I would like to use print_r(), but capature its output in a String,
to use
ain a generic logging infrastructure. But every call to print_r(),
var_dump(), var_export(), et. al. goes to STDOUT no matter what I do?

How to I get print_r() to return a string, and not go to STDOUT?


print_r($array, true);

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #2

P: n/a
"Berislav Lopac" <be************@dimedia.hr> writes:
Mark Evenson wrote:

[...]
How to I get print_r() to return a string, and not go to STDOUT?


print_r($array, true);


Alright. Works! Sorry I missed that in the documentation.

Thanks for your help.

--
Mark Evenson <ev*****@panix.com>

"A screaming comes across the sky. It has happened before, but there is
nothing to compare to it now."
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.