Skip to content

Instantly share code, notes, and snippets.

@sproutventure
Created September 27, 2011 17:06
Show Gist options
  • Save sproutventure/1245633 to your computer and use it in GitHub Desktop.
Save sproutventure/1245633 to your computer and use it in GitHub Desktop.
PHP Dev Helpers
<?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