PHP 实现终端进度条

普通进度条

$count = 100;
for ($i = 1; $i <= 100; $i++) {
    usleep(50000);
    printf("\r [%-100s] (%2d%%/%2d%%)", str_repeat("=", $i) . ">", ($i / $count) * 100, $count);
}

深度录屏_选择区域_20180726150648.gif

高逼格的进度条

for ($i = 1; $i <= 100; $i++) {
    usleep(50000);
    printf("\033 [31m\r [%-100s]\033 [0m (%2d%%/%2d%%)", str_repeat("=", $i) . ">", ($i / $count) * 100, $count);
}

深度录屏_选择区域_20180726150609.gif

发表评论