直接看代码:
1 <?php 2 function tosize($size){ 3 $s = $size; 4 $dw = "";#pow(2,40)是2的40次方。 5 if($s >= pow(2,40)){#1的10次方就是1024,types到kb就是一次方,kb到mb就是二次方..类推 6 $dw = "TB"; 7 }elseif($s >= pow(2,30)){ 8 $dw = "GB"; 9 }elseif($s >= pow(2,20)){ 10 $dw = "MB"; 11 }elseif($s >= pow(2,10)){ 12 $dw = "KB"; 13 }elseif($s >= pow(1,10)){ 14 $dw = "types"; 15 } 16 return $s.$dw; 17 } 18 echo tosize('10'); 19 ?>