Last active
July 24, 2023 23:44
-
-
Save reatlat/127aec7806bf3adc8606f5e27dd6e6c1 to your computer and use it in GitHub Desktop.
Debug pretty print for PHP
This file contains hidden or 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 | |
/** | |
* 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