Writing a PHP Coda Plugin

wp-carousel-20

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.

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

For much more information:
http://www.panic.com/coda/developer/howto/plugins.php