PHP使用適合閱讀的格式顯示文件大小的方法
更新時間:2015年03月05日 10:34:57 作者:紅薯
這篇文章主要介紹了PHP使用適合閱讀的格式顯示文件大小的方法,實例分析了php實現(xiàn)數(shù)據(jù)轉換的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了PHP使用適合閱讀的格式顯示文件大小的方法。分享給大家供大家參考。具體分析如下:
文件大小顯示,例如 1.7K , 2.9M
代碼如下:
復制代碼 代碼如下:
// A much better and accurate version can be found
// in Aidan's PHP Repository:
// http://aidanlister.com/repos/v/function.size_readable.php
/**
* Returns a human readable filesize
*
* @author wesman20 (php.net)
* @author Jonas John
* @version 0.3
* @link http://www.jonasjohn.de/snippets/php/readable-filesize.htm
*/
function HumanReadableFilesize($size) {
// Adapted from: http://www.php.net/manual/en/function.filesize.php
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}
// in Aidan's PHP Repository:
// http://aidanlister.com/repos/v/function.size_readable.php
/**
* Returns a human readable filesize
*
* @author wesman20 (php.net)
* @author Jonas John
* @version 0.3
* @link http://www.jonasjohn.de/snippets/php/readable-filesize.htm
*/
function HumanReadableFilesize($size) {
// Adapted from: http://www.php.net/manual/en/function.filesize.php
$mod = 1024;
$units = explode(' ','B KB MB GB TB PB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2) . ' ' . $units[$i];
}
希望本文所述對大家的php程序設計有所幫助。
相關文章
php preg_match_all結合str_replace替換內(nèi)容中所有img
最近做站的時候,采集了大量的數(shù)據(jù),但采回來的數(shù)據(jù)基本上都要經(jīng)過過濾原站保留的數(shù)據(jù),其中IMG就是一個地方。網(wǎng)站上好多這些應用例子似乎沒有必要“秀”出來,但站已幾天沒寫日志,那就來一個吧2008-10-10PHP使用mysql_fetch_object從查詢結果中獲取對象集的方法
這篇文章主要介紹了PHP使用mysql_fetch_object從查詢結果中獲取對象集的方法,實例分析了php操作mysql_fetch_object查詢數(shù)據(jù)庫的技巧,非常具有實用價值,需要的朋友可以參考下2015-03-03