首页 > 代码库 > PHP snippets
PHP snippets
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。