将整数字节值转换为速记字节值。
原型
wp_convert_bytes_to_hr( int $bytes )
参数
$bytes
(int)
(Required)
整数字节值。
返回值
(string)
简写字节值。
源文件
路径:wp-includes/deprecated.php
<?php
...
function wp_convert_bytes_to_hr( $bytes ) {
_deprecated_function( __FUNCTION__, '3.6.0', 'size_format()' );
$units = array( 0 => 'B', 1 => 'KB', 2 => 'MB', 3 => 'GB', 4 => 'TB' );
$log = log( $bytes, KB_IN_BYTES );
$power = (int) $log;
$size = pow( KB_IN_BYTES, $log - $power );
if ( ! is_nan( $size ) && array_key_exists( $power, $units ) ) {
$unit = $units[ $power ];
} else {
$size = $bytes;
$unit = $units[0];
}
return $size . $unit;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_convert_bytes_to_hr/