PHP cli从用户获取输入,然后转储到变量可能吗? [英] PHP cli getting input from user and then dumping into variable possible?

查看:64
本文介绍了PHP cli从用户获取输入,然后转储到变量可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用php cli从用户那里获取输入,然后将输入转储到变量中,然后脚本继续进行.

Is it possible to get input from a user using php cli and then dump the input into a variable and then the script goes ahead.

就像c ++ cin函数一样?

Just like the c++ cin function ?

如果可以,那怎么可能? 也许不仅是php,而且可能还有一些linux命令?

Is that possible if yes then how ? Maybe not only php but maybe with some linux commands ?

推荐答案

查看此PHP手册页 http://php.net/manual/zh/features.commandline.php

Have a look at this PHP manual page http://php.net/manual/en/features.commandline.php

尤其是

<?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;
}
echo "\n";
echo "Thank you, continuing...\n";
?>

这篇关于PHP cli从用户获取输入,然后转储到变量可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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