Friday 13 March 2009

Highlighting Perl code using PHP

The grand majority of highlighting (coloring) scripts that exist on the web today ignore the Perl language, but if you have the PEAR extension installed on your PHP-enabled webserver you can use the Text_Highlighter package to highlight many programming languages including Perl. But what if you don’t have PEAR installed and are unable to install it for one reason or another?

You may be aware of PHP’s in-build highlight functions:highlight_string() and highlight_file(). They both return or output highlighted PHP code. In order to get your code to be highlighted as PHP you have to stick the PHP opening and closing tags around it.

But did you know you can use these functions to highlight Perl code if you trick it into thinking it is PHP? Perl code is quite similar to PHP code so it does a reasonable job but it’s not perfect. In fact you have to do some pre and post processing. In my example below I have a Perl file which I want to highlight... Continue reading the article here: http://www.islamic-dictionary.com/blog/?p=59

(Copying and pasting didn't work - Blogger's code handling is worse than Wordpress's so that's why I'm linking to the other article)

2 comments:

  1. Perl is the best scripting language for Text processing and handle regex. I have posted few articles related to those at my blog

    http://icfun.blogspot.com/search/label/perl

    Also Perl's Cpan has lots of support that I don't even need to think extra while developing project. I didn't find such help on other programming language except Java and .NET

    ReplyDelete