Skip to content

Instantly share code, notes, and snippets.

@eypsilon
Last active December 1, 2020 01:25
Show Gist options
  • Select an option

  • Save eypsilon/cbe7784739bf0362cb7f144df0703c1b to your computer and use it in GitHub Desktop.

Select an option

Save eypsilon/cbe7784739bf0362cb7f144df0703c1b to your computer and use it in GitHub Desktop.
Simple Highlight String with PHPs highlight_string()
<?php
/**
* Dead simple Highlight String with PHPs highlight_string()
*
* If you just want some colorful output instead of real highlighting
*
* @param String|Array to highlight (auto prefixed with '<?php ')
* @return String the highlighted String (auto prefix removed)
*/
function highlightString($var) {
$rpl = '<span style="color: ' . \ini_get('highlight.default') . '">';
return \str_replace(
"{$rpl}&lt;?php&nbsp;", $rpl, \highlight_string('<?php ' . \print_r($var, true), true)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment