Prompt User At Command Line

Description: From the command line mode, prompt a user for keyboard input.

<?PHP
 
ECHO "Give me your name: ";
$data = FOPEN("php://stdin", "rb");
 
WHILE (1==1) {
   $chunk = FREAD($data, 1);
   IF ($chunk == "\n" || $chunk == "\r") BREAK;
   $input .= $chunk;
}
FCLOSE($data);
 
ECHO "Hello $input!\n";
 
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.