Created
December 5, 2012 01:32
-
-
Save shaneharter/4211173 to your computer and use it in GitHub Desktop.
Progress Display for PHP CLI scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for ($i=1; $i<101; $i++) { | |
progress($i, 100, 'Percent Complete: '); | |
usleep(25000); | |
} | |
function progress ($step_x, $of_y, $label = '') { | |
$p = number_format($step_x / $of_y * 100, 1) . '%'; | |
$p = str_pad($p, 5, ' ', STR_PAD_LEFT); | |
if ($label) | |
$p = "{$label} {$p}"; | |
echo str_repeat("\010", strlen($p)); | |
if ($step_x < $of_y) | |
echo $p; | |
else | |
echo str_repeat(' ', strlen($p)) . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment