1 Star 3 Fork 26

yg178/php-console

forked from inhere/php-console 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
progress_bar3.php 914 Bytes
一键复制 编辑 原始数据 按行查看 历史
<?php
/*
\r 回到行首
chr 转换为 ASCI 码
*/
/**
* @param int $total
* @param string $msg
* @param string $char
* @return Generator
*/
function progress_bar($total, $msg, $char = '=') {
$finished = false;
while (true) {
if ($finished) {
return;
}
$current = yield;
$progress = ceil(($current/$total) * 100);
if ($progress >= 100) {
$progress = 100;
$finished = true;
}
printf("\r[%-100s] %d%% %s",
str_repeat($char, $progress) . ($finished ? '' : '>'),
$progress,
$msg
);// ♥
if ($finished) {
echo "\n";
break;
}
}
}
$i = 0;
$total = 120;
$bar = progress_bar($total, 'Msg Text', '#');
echo "progress:\n";
while ($i <= $total) {
$bar->send($i);
usleep(50000);
$i++;
}
//var_dump($bar->valid());
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/hwsyy/php-console.git
git@gitee.com:hwsyy/php-console.git
hwsyy
php-console
php-console
master

搜索帮助