MIKESTOWE.COM

you are here

Simple PHP Highlighter Plugin

This simple HTMLe plugin allows you to highlight PHP code by including either a small block of text, or by setting a file.

Note: this plugin will be deprecated as of HTMLe 2.1, and will be replaced by the php plugin (which gives you the ability to run php code, grab superglobals, and highlight php code).

Plugin attributes:

text = the text you would like to be code highlighted (ie: <?php echo ‘hello world’; ?>)
file
= the file you would like to be code highlighted (ie: the highlightphp.php plugin file)

<?php
/*
 * HTMLe plugin
 * --------------------
 * File:     highlightphp.php
 * Type:     function
 * Name:     highlightphp
 * Purpose:  highlights php code
 * Author:   Michael Stowe
 * Example: {highlightphp text="<?php echo 'hello world';"} {highlightphp file="samplefile.php"}
 * Required: text {OR} file
 * Special: 
 * --------------------
 * Note: the above information should be included in all plugins and is used to teach 
 * the user about your plugin.  Use the required field for any required attributes, and
 * the special field for any special tags your plugin accepts.
 */

function HTMLe_highlightphp($params) {
    if(isset(
$params['text'])) {
        return 
highlight_string(htmlspecialchars_decode($params['text']),true);
    } elseif(isset(
$params['file'])) {
        return 
'<div style="width: 100%; overflow-x: auto;"><nowrap>'.str_replace('{','{<img width="1" height="1" style="display: none;">',highlight_file(getcwd().'/'.$params['file'],true)).'</nowrap></div>';
    } else {
        return 
'<!-- UNABLE TO HIGHLIGHT PHP... MISSING PARAMETERS -->';
    }
    
}

?>
Share this Page:
Facebook Twitter Linkedin Reddit Tumblr Email

Leave a Reply

Your email address will not be published. Required fields are marked *