php教程显示文章 几分钟前,几小时前,几天前发布类
文章发表时的unix时间戳,来转化为例如 几分钟前,几小时前,几天前 这样的提示。如微博
这看起来更加人性化
1 unit = 0 ; // is minutes,hour or day?
29
30 if($d_int 31 $this->rustle = $d_int;
32 $this->unit = 1;
33 }
34 else if($d_int 35 $this->rustle = floor($d_int/60);
36 $this->unit = 2 ;
37 }
38 else if($d_int 39 $this->rustle = floor($d_int/720);
40 $this->unit = 3 ;
41 }
42 else{
43 $this->rustle = $d ;
44 $this->unit = 4 ;
45 }
46 }
47 public function piece_str($c)
48 {
49 $this->count_int($c);
50
51 $u = '';
52 switch( $this->unit )
53 {
54 case 1:
55 $u = 'minute';
56 break;
57 case 2:
58 $u = 'hour';
59 break;
60 case 3:
61 $u = 'day';
62 break;
63 case 4:
64 $u = '';
65 break;
66 case 0:
67 return 'sorry , get time is fail';
68 }
69 if($this->unit 70 {
71 if($this->rustle > 1)
72 return (string)$this->rustle.$u.'s ago';
73 else if($this->rustle == 1)
74 return (string)$this->rustle.$u.'ago';
75 else
76 return 'just now';
77 }
78 }
79 /* example: $ago = timeago::getobject();
80 * echo $ago->piece_str($unix);
81 * // 2 days ago
82 */
83 }
84 ?>