physaux Posted August 11, 2010 Share Posted August 11, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/210488-how-can-i-save-debug-string-to-be-printed-later-if-i-want-to-print_rany_array/ Share on other sites More sharing options...
sinista Posted August 11, 2010 Share Posted August 11, 2010 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/210488-how-can-i-save-debug-string-to-be-printed-later-if-i-want-to-print_rany_array/#findComment-1098292 Share on other sites More sharing options...
DavidAM Posted August 11, 2010 Share Posted August 11, 2010 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"; Quote Link to comment https://forums.phpfreaks.com/topic/210488-how-can-i-save-debug-string-to-be-printed-later-if-i-want-to-print_rany_array/#findComment-1098294 Share on other sites More sharing options...
physaux Posted August 11, 2010 Author Share Posted August 11, 2010 Thanks that worked perfectly! Quote Link to comment https://forums.phpfreaks.com/topic/210488-how-can-i-save-debug-string-to-be-printed-later-if-i-want-to-print_rany_array/#findComment-1098297 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.