2

dump

dump
SYNOPSIS

dump($var, $label=null, $echo=true)

DESCRIPTION

dump returns a string containing the readable representation of $var in an HTML pre tag. If $echo is true, which is the case by default, the string is inserted in the output flow.

Assign a text to $label, typically the name of a variable, to label the output.

CODE
  1. function dump($var, $label=null, $echo=true) {
  2.     $label = ($label===null) ? '' : rtrim($label) . '=';
  3.  
  4.     ob_start();
  5.     var_dump($var);
  6.     $output = ob_get_clean();
  7.  
  8.     $output = preg_replace("/\]\=\>\n(\s+)/m", "] => ", $output);
  9.     if (PHP_SAPI == 'cli') {
  10.         $output = PHP_EOL . $label . $output . PHP_EOL;
  11.     }
  12.     else {
  13.         $output = htmlspecialchars($output, ENT_QUOTES, 'UTF-8');
  14.  
  15.         $output = '<pre><code>' . $label . $output . '</code></pre>' . PHP_EOL;
  16.     }
  17.  
  18.     if ($echo) {
  19.         echo $output;
  20.     }
  21.  
  22.     return $output;
  23. }

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

===

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].