码迷,mamicode.com
首页 > Web开发 > 详细

PHP snippets

时间:2014-12-10 15:51:32      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   os   sp   on   div   log   

Friendly file size string

 1 public static function bytesToSize($bytes)
 2 {
 3         if ($bytes < 1024) {
 4             return ‘< 1k‘;
 5         } else if ($bytes < 1048576) { // 1024 * 1024
 6             return round($bytes/1024, 2) .‘K‘;
 7         } else if ($bytes < 1073741824) { // 1024 * 1024 * 1024
 8             return round($bytes/1048576, 2) .‘M‘;
 9         } else {
10             return round($bytes/1073741824, 2) .‘G‘;
11         }
12 }

Duration of the song

 1 public static function secToStr($sec)
 2 {
 3         $hours = floor($sec / 3600);
 4         $minutes = floor(($sec / 60) % 60);
 5         $seconds = $sec % 60;
 6         
 7         if ($hours > 0) {
 8             return sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds);
 9         } else if ($minutes > 0) {
10             return sprintf("%d:%02d", $minutes, $seconds);
11         } else {
12             return sprintf("%d:%02d", $minutes, $seconds);
13         }
14 }

 

PHP snippets

标签:style   blog   io   color   os   sp   on   div   log   

原文地址:http://www.cnblogs.com/mztest/p/4155433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!