Using GeSHi
GeSHi is free software and it's really very simple to use it. If you are a user of for example WordPress you can find a plugin with syntax highlighting which uses GeSHi. I however don't belong to this group, so I had to make a workaround. I am using my own CMS and I type these lines in TinyMCE WYSIWYG editor. I call the following php method to highlight my code:
private function HighLightSyntax($code,$lang) { $geshi = new GeSHi($code,$lang); return $geshi->parse_code(); }//HighLightSyntax
This is of course from the context of one of my classes. The important part is inside this private method.
Before using this code I parse code contents from article content using special symbols. I use these symbols to enclose code. The final touch was a simple CSS formatting of code content, here it is:
div.code { width: 100%; overflow: auto; font-size: 1.1em; background: #373737 url(../img/code-bg.gif) left top repeat; }
And that's pretty much all there is :)