ASCII Progressbar

PHP  (17.07.2010 18:16) Diese PHP Klasse generiert eine ASCII Progressbar, wie man sie von wget kennt.

Quellcode (ausblenden | aufklappen)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
 
   class ascii_progressbar {
 
      private $width;
 
      function __construct($width) {
         $this->width = (int)$width;
      }
 
      public function get($percent) {
         $size = ((int)ceil($this->width/100*$percent));
         $spaces = (int)($this->width-$size);
         if($spaces>0) $spaces--; else $size--;
         $text = "[";
            if($size>0) $text .= str_repeat("=", ($spaces>0 ? ($size-1) : $size));
            if($spaces>0 && $size>0) $text.="&gt;";
            if($spaces>0) $text .= str_repeat("&nbsp;", $spaces);
         $text .= "] ".$percent."%";
         return $text;
      }
 
   }
 
?>