//echo convertUnit(“854.41 KB”);
/*转换单位*/
function convertUnit($size, $unit=’K’){
preg_match(‘/^(d+.d+)s*(w?)B?$/i’, $size, $o);
//var_dump(strtoupper($o[2]));
if(strtoupper($o[2]) == strtoupper($unit)) return $o[1]; // 单位相等,直接返回数字
$type = array( “B”, “K”, “M”, “G”, “T”, “P” );
$type = array_flip($type);
$mult = $type[$o[2]] – $type[$unit];
$num = $o[1] * pow(1024,$mult);
return $num;
//return $num.”$unit”.”B”;
}