欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > IT业 > laravel command 执行自定义命令 choice 以后使用info 中文乱码

laravel command 执行自定义命令 choice 以后使用info 中文乱码

2024/10/25 15:21:48 来源:https://blog.csdn.net/weixin_44475312/article/details/141958635  浏览:    关键词:laravel command 执行自定义命令 choice 以后使用info 中文乱码

laravel command 执行自定义命令 choice 以后使用info 中文乱码

    • 1. 代码
    • 2. 执行以后乱码
    • 3. 解决

1. 代码

<?phpnamespace App\Console\Commands;use Illuminate\Console\Command;class ProcessDataCommand extends Command
{// 命令的名称和签名protected $signature = 'process:data';// 命令的描述protected $description = 'Processing data with a progress bar and a selection';public function __construct(){parent::__construct();}public function handle(){// 提供选择的选项$type = $this->choice('Which type of data would you like to process?',['大', '中', '小'],0 // 默认选项);// 根据选择的类型设置需要处理的总数据量switch ($type) {case 'Small Data Set':$totalItems = 2;break;case 'Medium Data Set':$totalItems = 2;break;case 'Large Data Set':$totalItems = 2;break;default:$totalItems = 2;}// 创建进度条$bar = $this->output->createProgressBar($totalItems);// 启动进度条$bar->start();for ($i = 0; $i < $totalItems; $i++) {// 模拟处理任务sleep(1);// 进度条前进$bar->advance();}// 完成进度条$bar->finish();$this->info("执行完成 $type!");}
}

2. 执行以后乱码

在这里插入图片描述

3. 解决

配置php.ini,重启服务器

output_encoding =UTF-8

再次执行
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com