consonantCounter

#!/usr/bin/php
<?php
/**
 * "consonantCounter.php"
 * Written by Karl Wilbur <karl@karlwilbur.net>
 * Reads input file and return the word with the longest string of consonants.
 *
 * Input file is one word per line.
 *
 * Usage:
 * [With execute permission]
 * consonantCounter.php <filename>
 *
 * [Without execute permission]
 * php consonantCounter.php <filename>
 *
 */

$filename = $_SERVER['argv'][1];
if (!file_exists($filename)) die('File "'.$filename.'" does not exist.'."\n");
if (!is_readable($filename)) die('File "'.$filename.'" is not readable.'."\n");
error_reporting(0);

$words = array();
$lines = file($filename);
foreach ( $lines as $line) {
    $line = rtrim($line);
    $words[$line] = 0;
    preg_match_all("|[^aeiou]+|",$line,$matches);
    foreach($matches[0] as $v)
        $words[$line] = max($words[$line],strlen($v));
}

asort($words);
$longest = array_pop(array_keys($words));
echo $longest."\n";