我有一个自己编写的代码,还有另一个编码员编写的“Time ago”代码...
问题图片:
所以我的代码从数据库中获取时间戳:
echo "<h1> User hash: " . $link . "</h1><br>
<table border='1' width=100% BORDERCOLOR=LIME bgcolor='#000000'>
<tr>
<th>IP</th>
<th>Time</th>
<th>Browser</th>
<th>More info</th>
</tr>";
include 'timeago.php';
while($row = mysql_fetch_array($retval, MYSQL_NUM))
{
$time_ago = "{$row[1]}";
echo "
<tr>
<td align='center'>{$row[0]}</td>
<td align='center'>" .time_stamp($time_ago). "</td>
<td align='center'>{$row[3]}</td>
<td align='center'><a href='http://whatismyipaddress.com/ip/{$row[0]}' target='_blank'> More info here </a></td>
</tr>";
}
echo "</table>";
但如您所见,时间不在表格中,我不知道如何解决。
我用这段代码来转换:
<?php
//Php Time_Ago Script v1.0.0
//Scripted by D.Harish Kumar@TYSON567
function time_stamp($time_ago)
{
$cur_time=time();
$time_elapsed = $cur_time - $time_ago;
$seconds = $time_elapsed ;
$minutes = round($time_elapsed / 60 );
$hours = round($time_elapsed / 3600);
$days = round($time_elapsed / 86400 );
$weeks = round($time_elapsed / 604800);
$months = round($time_elapsed / 2600640 );
$years = round($time_elapsed / 31207680 );
// Seconds
if($seconds <= 60)
{
echo "$seconds seconds ago";
}
//Minutes
else if($minutes <=60)
{
if($minutes==1)
{
echo "one minute ago";
}
else
{
echo "$minutes minutes ago";
}
}
//Hours
else if($hours <=24)
{
if($hours==1)
{
echo "an hour ago";
}
else
{
echo "$hours hours ago";
}
}
//Days
else if($days <= 7)
{
if($days==1)
{
echo "yesterday";
}
else
{
echo "$days days ago";
}
}
//Weeks
else if($weeks <= 4.3)
{
if($weeks==1)
{
echo "a week ago";
}
else
{
echo "$weeks weeks ago";
}
}
//Months
else if($months <=12)
{
if($months==1)
{
echo "a month ago";
}
else
{
echo "$months months ago";
}
}
//Years
else
{
if($years==1)
{
echo "one year ago";
}
else
{
echo "$years years ago";
}
}
}
?>
我只需要将转换后的时间回显到表中。
最佳答案
在函数 time_stamp 中更改 echo 以返回
关于php - 如何从函数调用变量并在回显中回显它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22105069/