PHP等待来自命令行的输入 [英] PHP wait for input from command line

查看:1399
本文介绍了PHP等待来自命令行的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想能够让PHP程序等待用户的输入。例如:

I want to be able to let a PHP program wait for user's input. For example:


  1. 脚本从服务器请求授权代码(此代码将通过电子邮件发送)

  2. 脚本等待用户输入授权码

  3. 脚本继续

做步骤2? (可能吗?)

How should I do step 2? (Is it possible?)

推荐答案

cli的php手册页有详细解释一个解决方案(复制到这里为任何人寻找)

The php man page for the cli has a comment here detailing a solution, (copied here for anyone else looking)

<?php
echo "Are you sure you want to do this?  Type 'yes' to continue: ";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if(trim($line) != 'yes'){
    echo "ABORTING!\n";
    exit;
}
fclose($handle);
echo "\n"; 
echo "Thank you, continuing...\n";
?>

这篇关于PHP等待来自命令行的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆