Skip to content

Instantly share code, notes, and snippets.

@petercossey
Created May 16, 2012 00:18
Show Gist options
  • Save petercossey/2706212 to your computer and use it in GitHub Desktop.
Save petercossey/2706212 to your computer and use it in GitHub Desktop.
PHP scripting - record input from STDIN
<?php
function nfact($n) {
if ($n == 0) {
return 1;
}
else {
return $n * nfact($n - 1);
}
}
echo "\n\nPlease enter a whole number ... ";
$num = trim(fgets(STDIN));
// ===== PROCESS - Determing the factorial of the input number =====
$output = "\n\nFactorial " . $num . " = " . nfact($num) . "\n\n";
echo $output;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment