我希望能够让PHP程序等待用户的输入。例如:
我该如何做第2步? (有可能吗?)
答案 0 :(得分:142)
cli的php手册页有一个comment here详细说明了一个解决方案,(这里复制给其他人看)
<?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";
?>