PHP格式化字节

<?php

   function format_bytes($size, $delimiter = '') {
        $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
        for ($i = 0; $size >= 1024 && $i < 5; $i++) $size /= 1024;
        return round($size, 2) . $delimiter . $units[$i];
    }
    
    $size = format_bytes(123456);
    
    echo $size;

 

posted @ 2022-03-07 18:03  张喜龙  阅读(66)  评论(0编辑  收藏  举报