$10K coding deathmatch
Steve Dibb
steve at wonkabar.org
Wed Nov 1 14:40:59 MST 2006
Stephen Weeks wrote:
> Chris Carey wrote:
>
>> if (!file_exists($argv[1])) exit;
>> $input=@file($argv[1]);
>
>
> Ryan Byrd wrote:
>
>> $fp = fopen ($argv[1],"r");
>
>
> Josh Coates wrote:
>
>> your code should assume that the input is coming via standard input
>> (stdin)
Here's a function I use on my shell scripts, if that helps.
function ask($string, $default = false) {
if(is_string($string)) {
fwrite(STDOUT, "$string ");
$input = fread(STDIN, 255);
if($input == "\n") {
return $default;
}
else {
$input = trim($input);
return $input;
}
}
}
Steve
More information about the PLUG
mailing list