#native_company# #native_desc#
#native_cta#

HTML Highlighting Function

By Nicholas Sack
on July 15, 2004

Version: 1.0

Type: Function

Category: Other

License: GNU General Public License

Description: This function uses regular expressions to take HTML input and output it as easy-to-read syntax highlighted code.

<?

function highlight_html($code)
{
    $code = htmlentities($code);
    $code = preg_replace("/([a-zA-Z_]+)=/", "<font color="#FF0000">$1=</font>", $code);
    $code = preg_replace("/(&lt;[/a-zA-Z0-9&;]+)/", "<font color="#0000FF">$1</font>", $code);
    $code = str_replace("&lt;!--", "<font color="#008080">&lt;!--", $code);
    $code = str_replace("--&gt;", "--&gt;</font>", $code);
    $code = preg_replace("/[rn]+/", "n", $code);
    return $code;
}

?>