Writing a PHP Coda Plugin


Sound like a right pain in the arse? It’s surprisingly simple actually….

The steps to creating a simple locally run php Coda plugin:

You must have php installed and running locally.
Start the plugin file with theses lines:

#!/usr/bin/php -q
< ?php

(no space between < and ?php) Where /use/bin/php is the path to you local php install

This is an example of replacing a text string with an imaginary tag ‘harry’ around it.

/* a coda plugin */
$input = "";
$fp = fopen("php://stdin", "r");
while ( $line = fgets($fp, 1024) )
	$input .= $line;
// so now we have input text in $input
print '<harry>' . $input . '</harry>';

For much more information: