note 123534 added to function.highlight-string
| From: | pyetrosafe at gmail dot com | Date: | Sat, 19 Jan 2019 19:11:10 +0000 |
| Subject: | note 123534 added to function.highlight-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-210081@lists.php.net to get a copy of this message | ||
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}\"\\>)(<\\?php )(.*?)(\\</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 );
?>
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.35 (proxied: 2605:fe80:2100:a01e::25a5)
----
Manual Page -- http://php.net/manual/en/function.highlight-string.php
Edit -- https://master.php.net/note/edit/123534
Del: integrated -- https://master.php.net/note/delete/123534/integrated
Del: useless -- https://master.php.net/note/delete/123534/useless
Del: bad code -- https://master.php.net/note/delete/123534/bad+code
Del: spam -- https://master.php.net/note/delete/123534/spam
Del: non-english -- https://master.php.net/note/delete/123534/non-english
Del: in docs -- https://master.php.net/note/delete/123534/in+docs
Del: other reasons-- https://master.php.net/note/delete/123534
Reject -- https://master.php.net/note/reject/123534
Search -- https://master.php.net/manage/user-notes.php