optima header image by norlies.de norlies.de

Highlight several code on your website

I have released a new PHP5-class (class.highlight.php) which makes it very easy for you to highlight several lines of code on your website. It generates output of valid XHTML using ordered - or unordered lists for the code-lines.
Online source highlighter: test it
View class-documentation

Currently, the following programming-languages are suppurted: C++, CSS, DIFF, DTD, HTML, Java, JavaScript, MySQL, Perl, PHP, Python, Ruby, SQL and XML.

The class requires an actual PEAR - Installation on the webserver and the package Text_Highlighter.

You can highlight strings, files or contents with several programming languages. To highlight different code inside a content set a tag <pre lang=”code_language”>CODE</pre> around the snippet. code_language stands for your programming-language in which the the snippet should be highlighted.

To use this class f.e. for highlighting a content-file on your website, only 4 lines needed:

highlight_content_file('example-content.html'); echo( $hl->output() ); ?>

Code-formating is stored in a CSS-File and this, for sure, can be modified as you need.

If you don’t want to highlight source-code on the fly or you are not able to install PEAR on your webserver (f.e. because of missing root-access) or you simply want to checkout how it works, use my Online source highlighter. You can copy and paste the generated code to integrate it in your website.

Downloads for source-code highlighting
Description Type Filesize Link
PHP5 class, documentation, CSS-files, example .TAR 110 KB class-highlighter.tar
CSS-files for code-highlighting (dark and bright) .ZIP 1.2 KB code-css.zip

You can also find these resources on PHPClasses.org:
Source code highlighting on PHPClasses.org

Eine Antwort auf “Highlight several code on your website”

  1. Thank you for this project.

Antwort schreiben







php(dot)net mysql gentoo GNU Linux Valid XHTML 1.0 Strict RSS Feed für Einträge RSS Feed für Kommentare

kostenloser Counter

yoomanity - Einfach mal was Gutes tun