Tag Archives: syntax

Highlight Your PHP Code Syntax with the WordPress Plugin, SyntaxHighlighter Evolved! CodeUnit 06 JAN 2012

A website like this one involves the posting of a lot of code snippets and examples in a variety of development languages. Because code often looks a lot like a plain old bunch of textual gibberish, the ability to syntax-highlight the entry immediately makes it recognizable and thus useful to a programmer reading the entry.

WordPress.com has a useful feature built into it where it can automatically syntax-highlight code when placed within special shortcode markers, based on work by Alex Gorbatchev. Plugin author Viper007Bond together with the official Automattic company have taken this a little further, wrapping it up in a WordPress plugin form and releasing it to the public at large as SyntaxHighlighter Evolved!

Featuring support for a wide variety of languages, highlighting your code syntax is as easy as writing

[ php ]code[ /php ]

The plugin takes care of html entities and all that sort of encoding stuff, meaning that you don’t have to manually change your snippet in order for WordPress to properly display it! In addition, there are plenty of options you can employ within the shortcode blocks in order to extend the display functionality, like adding highlighted rows, line numbers, etc.

Powerful (and really useful) stuff! :)

Related Link: http://wordpress.org/extend/plugins/syntaxhighlighter

Check a PHP File for Syntax Errors from the Command Line CodeUnit 23 JAN 2010

I sometimes find myself having to create PHP scripts from scratch using Nano on a command line only interface on a Ubuntu Linux server. Obviously this kind of sucks if you are used to using a proper error-checking and code hinting full IDE like Aptana to help speed up your scripting, but hey, you can’t always have things your way.

Anyway, the point of this quickfire post is to remind you of PHP’s built in syntax checker that comes bundled in with the main PHP executable as a switch…

…namely the -l (lowercase ‘L’) switch.

Simply point the php -l command at the PHP file you wish to check for syntax errors (via a command prompt if you’re using Windows or a terminal if you’re partaking in the Linux experience) and the application will spit out a result for you, hopefully the much appreciated “No syntax errors detected in scriptname” success string.

A nice and simple way of ensuring that your PHP script at least passes all the compiler tests in terms of syntax and will actually run when executed. :)

Related Link: http://php.net/manual/en/features.commandline.php