Created
June 2, 2012 23:55
-
-
Save mayconbordin/2860547 to your computer and use it in GitHub Desktop.
PHP CLI progress bar in 5 lines of code
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
<?php | |
function progress_bar($done, $total, $info="", $width=50) { | |
$perc = round(($done * 100) / $total); | |
$bar = round(($width * $perc) / 100); | |
return sprintf("%s%%[%s>%s]%s\r", $perc, str_repeat("=", $bar), str_repeat(" ", $width-$bar), $info); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it's more consistent to use
floor
instead ofround
. And whyreturn
, simply echo the output.