28 строки
558 Б
PHP
28 строки
558 Б
PHP
<?php
|
|
|
|
function parsetime($str) {
|
|
$str=explode(',',$str);
|
|
$secs=0;
|
|
foreach ($str as $ent) {
|
|
if (preg_match('/^(\d+)([smhdwMy])$/',$ent,$mat)!==1)
|
|
return(false);
|
|
$mat[1]+=0;
|
|
if ($mat[2]=='s')
|
|
$secs+=$mat[1];
|
|
elseif ($mat[2]=='m')
|
|
$secs+=$mat[1]*60;
|
|
elseif ($mat[2]=='h')
|
|
$secs+=$mat[1]*60*60;
|
|
elseif ($mat[2]=='d')
|
|
$secs+=$mat[1]*60*60*24;
|
|
elseif ($mat[2]=='w')
|
|
$secs+=$mat[1]*60*60*24*7;
|
|
elseif ($mat[2]=='M')
|
|
$secs+=$mat[1]*60*60*24*31;
|
|
elseif ($mat[2]=='y')
|
|
$secs+=$mat[1]*60*60*24*365;
|
|
}
|
|
return $secs;
|
|
}
|
|
|
|
?>
|