Skip to content

Instantly share code, notes, and snippets.

@reid
Created October 8, 2008 20:44
Show Gist options
  • Save reid/15584 to your computer and use it in GitHub Desktop.
Save reid/15584 to your computer and use it in GitHub Desktop.
Transform a Colloquy.app conversation into a simpler format
<?php
$notice = $_SERVER['argv'][1] == '-notice';
$input = '';
if (STDIN) while (!feof(STDIN)) $input .= fgets(STDIN, 4096);
foreach (explode("\n", $input) as $text) {
$a = explode('<', $text);
if (count($a) > 1) {
$name = array_shift(explode('>', $a[1]));
} else if (strpos($text, ']')) {
$name = $notice;
} else {
$message = trim($a[0]);
if ($name && $message) {
echo ($name === true) ? "$message\n" : "$name: $message\n";
$name = $message = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment