Skip to content

Instantly share code, notes, and snippets.

@reatlat
Last active July 24, 2023 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reatlat/127aec7806bf3adc8606f5e27dd6e6c1 to your computer and use it in GitHub Desktop.
Save reatlat/127aec7806bf3adc8606f5e27dd6e6c1 to your computer and use it in GitHub Desktop.
Debug pretty print for PHP
<?php
/**
* Debug pretty print
* @author https://github.com/reatlat
*/
if (!function_exists('php_pretty_print')) :
/**
* Debug helper
* Pretty print the array
*/
function php_pretty_print($value = '', $inline = false)
{
switch ( $type = gettype( $value ) )
{
case $type === 'object' || $type === 'array':
$ret = print_r( $value, true );
break;
case $type === 'NULL':
$ret = $type;
break;
default:
$ret = '[ ' . $type . ' ] ' . htmlentities( $value );
}
if ($inline) {
echo '<style>
.php-debug {
background: #ffffff;
color: #000000;
border: 2px dashed #ffba00;
margin: 20px;
padding: 20px;
position: relative;
}
.php-debug::before {
content: "[DEBUG]";
position: absolute;
top: 0;
right: 0;
color: #000000;
padding: 1em 2em;
}
</style>';
} else {
/**
* Display properly formatted debug information.
*/
echo '<style>
.php-debug {
position: fixed;
overflow: auto;
z-index: 99999;
left: 0;
max-height: 40px;
bottom: 0;
width: 100%;
height: auto;
padding: 1em 2em;
background: #292929;
color: #fff;
opacity: 0.92;
margin: 0;
transition: all .3s ease;
}
.php-debug:active,
.php-debug:hover {
max-height: 50%;
}
.php-debug::before {
content: "[DEBUG]";
position: absolute;
top: 0;
right: 0;
color: yellow;
padding: 1em 2em;
}
</style>';
}
echo '<pre class="php-debug">' . $ret . '</pre>';
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment