发布于 5年前

PHP-CLI 获取命令行输入

普通 PHP-CLI 中

private function getInputConfirm()
{
    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";
}

在 Laravel Console 中

$this->confirm('Do you wish to continue?')

相关文章

©2020 edoou.com   京ICP备16001874号-3