How to creating code highlighted blocks on your website
I have written a small PHP framework and I want to make a website where I explain some basic features.
I want to display blocks of php code. Is there an easy to do this, preferably without JavaScript.
I want to have section kind of like displayed below:
// This function takes in a value and return it
public function getname($name){
r开发者_开发百科eturn $name;
}
For the server-side there are a few options already out there:
- The built-in
highlight_file
andhighlight_string
- Highlight source code in your PHP application
- GeSHi - Generic Syntax Highlighter
- CHIP: Code Highlighting in PHP
There are others, but just letting you know there are libraries available.
On my Tumblr blog I use Prettify for syntax highlighting. You can have a look here.
I'm really pleased with its simplicity and it support a lot of languages out of the box.
You can take a look at http://alexgorbatchev.com/wiki/SyntaxHighlighter
精彩评论