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!

Link to comment
Share on other sites

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;
}
?>

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.