对php编程一点不懂,请教:
想实现,*分钟前(*小时前...),不知道怎么编,在网上找到一段代码,很好用,也很简单:
- PHP code
'年',
'2592000'=>'个月',
'604800'=>'星期',
'86400'=>'天',
'3600'=>'小时',
'60'=>'分钟',
'1'=>'秒'
);
foreach ($f as $k=>$v)
{
if (0 != $c=floor($t/(int)$k))
{
return $c.$v.'前';
}
}
}
echo format_time('1336880454');
?>
但是这里时间需要转换为Unix时间戳,也找到一段代码:
- PHP code
现在页面的代码是这样的:
- PHP code
=date("Y-m-d ",strtotime($row["pay_time"]))?>
问题:想把上面三个代码整合在一起,实现我需要的,*分钟前(*小时前...),该如何搞?
------解决方案--------------------
- PHP code
'年',
'2592000'=>'个月',
'604800'=>'星期',
'86400'=>'天',
'3600'=>'小时',
'60'=>'分钟',
'1'=>'秒'
);
foreach ($f as $k=>$v)
{
if (0 != $c=floor($t/(int)$k))
{
return $c.$v.'前';
}
}
}
while ($row = mysql_fetch_array($rs_tmmsm)) {
echo format_time(strtotime($row["pay_time"]));
}
?>