update page now
Longhorn PHP 2026 - Call For Papers

Voting

: seven plus zero?
(Example: nine)

The Note You're Voting On

pyetrosafe at gmail dot com
7 years ago
I read the note from "stanislav dot eckert at vizson dot de" and I really enjoyed the function he created.
For my use I made some adaptations leaving the function more practical and allowing the passage and multiple parameters at a time, I also modified the style of the <code> element with a black background and margins.

<?php

// Combined of the highlight_string and var_export
function hl_export()
{
    try {
        ini_set("highlight.comment", "#008000");
        ini_set("highlight.default", "#FFFFFF");
        ini_set("highlight.html", "#808080");
        ini_set("highlight.keyword", "#0099FF; font-weight: bold");
        ini_set("highlight.string", "#99FF99");

        $vars = func_get_args();

        foreach ( $vars as $var ) {
            $output = var_export($var, true);
            $output = trim($output);
            $output = highlight_string("<?php " . $output, true);  // highlight_string() requires opening PHP tag or otherwise it will not colorize the text
            $output = preg_replace("|\\<code\\>|", "<code style='background-color: #000000; padding: 10px; margin: 10px; display: block; font: 12px Consolas;'>", $output, 1);  // edit prefix
            $output = preg_replace("|(\\<span style\\=\"color\\: #[a-fA-F0-9]{0,6}\"\\>)(&lt;\\?php&nbsp;)(.*?)(\\</span\\>)|", "\$1\$3\$4", $output);  // remove custom added "<?php "
            echo $output;
        }
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}

// Debug multiple vars at once.
$var1 = 'Example String';
$var2 = 1987;
$var3 = null;
$var4 = true;
$var5 = array('Array', '05', 05, false, null);

hl_export( $var1, $var2, $var3, $var4, $var5 );
?>

<< Back to user notes page

To Top