public
Created — forked from Gipetto/php_helpers.php

PHP Dev Helpers

  • Download Gist
php_helpers.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<?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);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.