Jump to content

How can I save debug string to be printed later if I want to print_r($any_array)


physaux

Recommended Posts

So I have been printing out some debug information, and now I am trying to instead save it to a string, which I will print out at the end of the page. Here is some specific problematic code:

 

$myplugin_debug_test.= "\n[GETTING COOKIES...\n";
	$myplugin_debug_test.= print_r($myplugin_all_cookies);//THIS IS LINE 38
	$myplugin_debug_test.= "\n... DONE]<br/>\n";

 

However, when I do this I get the following error:

 

Warning: Cannot modify header information - headers already sent by (output started at ...:38

 

So my question is how can I output the array data into a string, so that I can print it out later.

Like what am I doing wrong? Is there a better way to do this?

 

Thanks!

i dunno if this is what you mean but, put each string into array part then loop through the array later on

 

<?php
$myplugin_debug_test[] = "line 1 ";
$myplugin_debug_test[] = "line 2 ";
$myplugin_debug_test[] = "line 3 ";



#at the end of the page--->
foreach($myplugin_debug_test as $a)
{
    echo $a;
}
?>

There is a little-used second parameter to print_r() called $return. Set this to true to have the string returned instead of output to the browser:

 

$myplugin_debug_test.= "\n[GETTING COOKIES...\n";
$myplugin_debug_test.= print_r($myplugin_all_cookies, true);//THIS IS LINE 38
$myplugin_debug_test.= "\n... DONE]<br/>\n";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.