Home > php教程 > php手册 > body text

最快方法计算文件大小,输出' B', ' KB'

WBOY
Release: 2016-06-06 19:35:13
Original
945 people have browsed it

目前为止,发现可能是最快的计算方法 是不是还有更快的呢? PHP ?phpdate_default_timezone_set('UTC');function format_bytes($size){ $arr = array(' B', ' KB', ' MB', ' GB', ' TB'); for ($f = 0; $size = 1024 $f 4; $f++){$size /= 1024; }return roun

目前为止,发现可能是最快的计算方法
是不是还有更快的呢? PHP
<?php
date_default_timezone_set('UTC');

function format_bytes($size)
{ 
	$arr = array(' B', ' KB', ' MB', ' GB', ' TB'); 
	for ($f = 0; $size >= 1024 && $f < 4; $f++)
	{
		$size /= 1024; 
	}
	return round($size, 2).$arr[$f]; 
}
echo format_bytes('123456789');
?>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!