#!/usr/local/bin/php -d register_argc_argv=1
<?php

if ($argc 2) {
    
fprintf(STDERR"Need a file name as first argument!\n");
    exit(
1);
}

$file fopen($argv[1], 'rb');
if (
$file == false) {
    
fprintf(STDERR"File open failed!\n");
    exit(
1);
}
$line '';
$longest '';
$longest_on 0;
$num_lines 0;

for (
$num_lines ; ($line fgets($file)) != false $num_lines++) {
    if (
strlen($line) > strlen($longest)) {
        
$longest $line;
        
$longest_on $num_lines;
    }
}

if (
$longest_on) {
    echo 
'File had total of '$num_lines' lines.'"\n";
    echo 
'Longest line found on line '$longest_on' with 'strlen($longest), ' characters.'"\n";
    echo 
'The line was: '$longest;
}
else {
    
fprintf(STDERR"The file had no readable lines!\n");
}