I want to write a PHP script that I can use from the command line. I want it to prompt and accept input for a few items, and then spit out some results. I want to do this in
From PHP: Read from Keyboard – Get User Input from Keyboard Console by Typing:
You need a special file:
php://stdin
which stands for the standard input.
print "Type your message. Type '.' on a line by itself when you're done.\n";
$fp = fopen('php://stdin', 'r');
$last_line = false;
$message = '';
while (!$last_line) {
$next_line = fgets($fp, 1024); // read the special file to get the user input from keyboard
if (".\n" == $next_line) {
$last_line = true;
} else {
$message .= $next_line;
}
}