Created
September 27, 2011 17:06
-
-
Save sproutventure/1245633 to your computer and use it in GitHub Desktop.
PHP Dev Helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function pp() { | |
$msg = __v_build_message(func_get_args()); | |
echo '<pre style="white-space:pre-wrap; text-align: left; '. | |
'font: normal normal 11px/1.4 menlo, monaco, monospaced; '. | |
'background: white; color: black; padding: 5px;">'.$msg.'</pre>'; | |
} | |
function dp() { | |
$msg = __v_build_message(func_get_args(), 'var_dump'); | |
echo '<pre style="white-space:pre-wrap;; text-align: left; '. | |
'font: normal normal 11px/1.4 menlo, monaco, monospaced; '. | |
'background: white; color: black; padding: 5px;">'.$msg.'</pre>'; | |
} | |
function ep() { | |
$msg = __v_build_message(func_get_args()); | |
error_log('**: '.$msg); | |
} | |
function __v_build_message($vars, $func = 'print_r', $sep = ', ') { | |
$msgs = array(); | |
if (!empty($vars)) { | |
foreach ($vars as $var) { | |
if (is_bool($var)) { | |
$msgs[] = ($var ? 'true' : 'false'); | |
} | |
elseif (is_scalar($var)) { | |
$msgs[] = $var; | |
} | |
else { | |
switch ($func) { | |
case 'print_r': | |
case 'var_export': | |
$msgs[] = $func($var, true); | |
break; | |
case 'var_dump': | |
ob_start(); | |
var_dump($var); | |
$msgs[] = ob_get_clean(); | |
break; | |
} | |
} | |
} | |
} | |
return implode($sep, $msgs); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment