Last active
December 1, 2020 01:25
-
-
Save eypsilon/cbe7784739bf0362cb7f144df0703c1b to your computer and use it in GitHub Desktop.
Simple Highlight String with PHPs highlight_string()
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 | |
| /** | |
| * 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}<?php ", $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