-
Recent Posts
Recent Comments
- petruchek on Confession of the occasional blogger
- petruchek on Confession of the occasional blogger
- Paul Synnott on Google Chrome: Use Space Bar to Confirm Form Resubmission
- Andrew Gunn on Google Chrome: Use Space Bar to Confirm Form Resubmission
- Andrei on Format file size
Archives
Categories
Meta
Tag Archives: snippet
Get number of days in month with PHP
Problem: get number of days in certain month with PHP, if $m – is a month and $y – is an year. First solution, hacker-style (source): (31 - (($m - 1) % 7 % 2) - ((($m == 2) << !!($y % 4)))) ?> This solution doesn’t work properly for years divisible by 100, and non-divisible by … Continue reading
Format file size
Code snippet to output number of bytes with unknown capacity: function format_filesize($bytes) { if ($bytes == 0) return ’0.00 B’; $s = array(‘B’, ’Kb’, ’MB’, ’GB’, ’TB’, ’PB’); $e = floor(log($bytes)/log(1024)); return sprintf(‘%.2f ’.$s[$e], ($bytes/pow(1024, floor($e)))); } I don’t know the author of this code.