Chris Nizzardini, Salt Lake City Utah, Web Developer Specializing in LAMP+Ajax Since 2006

My Blog

Here is my awesome blog. You can find information on programming, linux, documentation, tips for code and database optimization, my thoughts and rants, and whatever else I feel like sharing. Feel free to contribute to the blog by posting comments and asking questions.
Programming

Dumping PHP Array Data and debug_print_backtrace

By default you cannot write a print_r, var_dump, or debug_print_backtrace to a log in PHP. When you call these methods, PHP immediately echo’s out the data. Instead you must use PHPs ob_start which instructs PHP to not output anything from the script. To access the contents of the buffer use ob_get_contents and to let PHP know its okay to output from your script once again call ob_end_clean.

1
2
3
4
	ob_start();
	var_dump(debug_backtrace());
	$backtrace=ob_get_contents();
	ob_end_clean();

Related posts:

  1. capturing and storing echo or include data into a php variable
  2. Convert a PHP Object to an Array
  3. sorting a multidimensional array in php
  4. using php debug_print_backtrace for debugging code
  5. form checkboxes in php array and storing variables in url string

Tags:

Leave a Reply