Wordpress PHP syntax highlighting

Posted in Development, php on March 30, 2006

I've been writing code in my spare time again and have been wanting to blog little snippets but Wordpress munges any code that I add into the post body. I googled for wordpress plugins and most didn't support WP 2 or were a bit tame but then look what I found.

The iG:Syntax Hiliter by Amit Gupta. Just download, extract, upload to your wp-content/plugins folder, enable within the admin screen and Bob's your mum's brother.

Let's try it out:

$animals = array( "cow" => "moo", "sheep" => "baa", "dog" => "woof");

foreach ($animals as $animal => $noise) { print "I am a " . $animal . " and I make a " . $noise . " noisen"; }

[mysql]

CREATE TABLE Instance ( ID int(11) NOT NULL auto_increment, Site varchar(255) NOT NULL default '', App varchar(255) NOT NULL default '', Passwd varchar(32) default NULL, Expires int(11) default NULL, Archive tinyint(1) default NULL, PRIMARY KEY (ID), UNIQUE KEY instance_site_app_uniq (Site,App) ) TYPE=InnoDB;[/mysql]

[css]body { margin: 0; padding: 0; font-size: 68%; /* Resets 1em to 10px */ font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; background-color: #CCC; color: #333; }

#page { background-color: white; border: 1px solid #959596; margin: 20px auto; padding: 0; }

[/css]

[html]

Bealers.com

[/html]

[perl]#!/usr/bin/perl -w

use strict;

my $dumpDir = "/export/backup"; my $mysqlBin = "/usr/bin"; my $mysqlPassword = "foo";

foreach (ls -F /usr/local/mysql/var) { if (///) { chomp; s//$//; # remove the trailing / now my $dumpFile = "$dumpDir/$.sql"; my $dumpCommand = "$mysqlBin/mysqldump -celqF --password=$mysqlPassword $ > $dumpFile"; system $dumpCommand; # or warn "mysqlDump of $_ failed"; } }[/perl]

As a nice value-add (like it needed to do any more) he's also included the relevant code to add buttons to the content addition textarea (assuming you've disabled the dynamic one) so it surrounds your code with the relevant markers.

What a great plug-in.

Related:

Comments (0)