PHPBuilder - HTML Highlighting Function



RSS Twitter
Snippets Other

HTML Highlighting Function

by: Nicholas Sack
|
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("/[\r\n]+/", "\n", $code);
    return $code;
}

?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Nicholas Sack

Comment:



Comment:

(Maximum characters: 1200). You have characters left.