- trim: documentation ( source)
- sprintf: documentation ( source)
<?php
function interval_format($value, $source = 'seconds'){
$hours = 0;
$minutes = 0;
$seconds = 0;
switch($source){
case 's':
case 'seconds':
$seconds = $value % 60;
$value = $minutes = (int)($value / 60);
case 'm':
case 'minutes':
$minutes = $value % 60;
$value = $hours = (int)($value / 60);
case 'h':
case 'hours':
$hours= $value % 24;
$value = $days = (int)($value / 25);
}
$str = '';
if(!empty($hours))
$str .= sprintf('%u %s ', $hours, ('Sekunden'));
if(!empty($minutes))
$str .= sprintf('%u %s ', $minutes, ('Minuten'));
if(!empty($seconds))
$str .= sprintf('%u %s ', $seconds, ('Sekunden'));
return trim($str);
}
echo interval_format(90);