views:

136

answers:

3

I'm looking for a open source PHP script to colorize the code inside

<code></code> 

or

[code][/code] tags.

Thanks

+1  A: 

Assuming you want something other than the built-in syntax highlighter, GeSHi looks like it might fit your requirements:

GeSHi started as an idea to create a generic syntax highlighter for the phpBB forum system, but has been generalised to this project. GeSHi aims to be a simple but powerful highlighting class, with the following goals:

  • Support for a wide range of popular languages
  • Easy to add a new language for highlighting
  • Highly customisable output formats
ChrisF
Thanks! But.. Have you tested this script? It looks like I have to preselect the language before the output. I am looking for a more general colorization.
cvack
@cvack - If you go over to http://meta.stackoverflow.com and look at some on the questions on SO's syntax highlighting you'll see that a generic solution isn't really possible. What's a keyword in one application isn't in another etc. so there'll be errors and inaccuracies in the output. By specifying the language you can do a much better (if not perfect) job. Do you have a specific requirement that means you can't preselect the language?
ChrisF
I'm using MarkItUp jQuery editor and I have no idea how to make a language selecter ;) But thanks anyway!
cvack
A: 

PHP has some built in functions for this purpose. Check if highlight_string or highlight_file will work for you

http://www.php.net/highlight_file

http://www.php.net/highlight_string

MANCHUCK
+3  A: 

You could also try a clientside/javascript highlighter:
http://code.google.com/p/google-code-prettify/

  • Supports all C-like, Bash-like, and XML-like languages.

(This is the one used on stackoverflow.com/ and code.google.com/)

Bob Fanger
SWEET. Just what i was looking for.thanks :)
cvack