fwrite(STDOUT,'Please enter your name: '); print'The name you entered is: '.fgets(STDIN);
执行结果如下
1 2 3
php test.php Please enter your name: helen The name you entered is: helen
你也可以这么干,不让用户输入空内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$fs = true;
do { if ($fs) { fwrite(STDOUT, 'Please enter your name:'); $fs = false; } else { fwrite(STDOUT, 'Sorry, the name cannot be empty, please re-enter your name:'); }