Highlight PHPS code on Nginx

Hey there all,

since I mostly develop in PHP language, I wanted a way to share my code for a while, just to show it to a friend or so, without pasting the code into pastebin.

For such situations PHP created the extension PHPS, which stands for “PHP Source”. on Apache for ex. all you have to do is to add to httpd.conf file the line “AddType application/x-httpd-php-source .phps”, and phps extensioned files will be highlighted.

On Nginx however, there’s no such thing, some will say for good. After a little search i found that many Nginx users already created their own code to highight their PHPS files. but if we make the highlight ourselves, why not to take it into a completely new level? I’ve decided to add more features, such as line numbering. I looked over the www if anyone already wrote such thing. the best solution i saw can be found here. I’ve decided to use it and to add more features, like anchoring the lines, so i’ll be able to point the viewer to a specific line.

I also created a demo, so you can try it without running it yourself.

At last, I uploaded my work, including the Nginx configurations into GitHub, and it can be viewed over here. If you have any ideas to improve the code or you found a bug, I’ll be more than glad to have your feedback!

Dor.

4 thoughts on “Highlight PHPS code on Nginx

  1. Why aren’t you highlight HTML code as well?

    Anyway, I suggest removing the line numbering and using a counter on :before selector for each line. Not only it removes some of the logic required and let the browser do it itself, but it also helps us to copy content from the browser window without getting the line numbers.

  2. adding line-height: 15px; for .num class & line-height: 15px; for span tag will fix line hight problem

Leave a Reply

Your email address will not be published. Required fields are marked *