PHP Time Call Issue
Do not understand the PHP programming, ask:
Want to achieve, * minutes ago (* hours ago ...) ), do not know how to compile, find a piece of code on the Internet, very useful, but also very simple:
PHP Code
' Year ', ' 2592000 ' = ' month ', ' 604800 ' = ' Week ', ' 86400 ' and ' Day ', ' 3600 ' = ' ' hours ', ' x ' and ' Minutes ', ' 1 ' = ' s ' ); foreach ($f as $k = + $v) { if (0! = $c =floor ($t/(int) $k)) { return $c. $v. ' ago '; } } echo format_time (' 1336880454 '); ? >
But here time needs to be converted to a Unix timestamp, and a piece of code is found:
PHP Code
Now the code for the page is this:
PHP Code
", Strtotime ($row [" Pay_time "])?>
Question: Want to integrate the above three code together, achieve what I need, * minutes ago (* hours ago ...) ), how to do?
------Solution--------------------
PHP code
!--? PHP function Format_time ($time) {$t =time ()-$time; $f =array (' 31536000 ' =--> ' years ', ' 2592000 ' + ' month ', ' 604800 ' + ' Week ', ' 86400 ' + ' Day ', ' 3600 ' = ' hours ', ' the ' + ' ' minutes ', ' 1 ' = ' s '; foreach ($f as $k = + $v) {if (0! = $c =floor ($t/(int) $k)) {return $c. $v. ' former '; }}} while ($row = mysql_fetch_array ($rs _tmmsm)) {echo format_time (Strtotime ($row ["pay_time"]);}?