php教程显示文章 几分钟前,几小时前,几天前发布类
文章发表时的UNIX时间戳,来转化为例如 几分钟前,几小时前,几天前 这样的提示。如微博
这看起来更加人性化
1
2 class timeAgo
3 {
4 static $timeagoObject;
5 private $rustle;
6 private $unit;
7
8 private function __construct()
9 {
10
11 }
12 private function __clone(){ }
13 public static function getObject()
14 {
15 if(! (self::$timeagoObject instanceof self) )
16 self::$timeagoObject = new timeAgo();
17
18 return self::$timeagoObject;
19 }
20 private function count_int($unix_C) // main function
21 {
22 if(! (isset($unix_C) || is_numeric($unix_C)) )
23 return 'don't find parameter';
24
25 $d = time()-$unix_C ; // $d - unix time difference value
26 $d_int =(int)floor($d/60) ; // minimum unit -- minutes unix/60
27
28 $this->unit = 0 ; // is minutes,hour or day?
29
30 if($d_int < 60){ // minutes in one hour 3600
31 $this->rustle = $d_int;
32 $this->unit = 1;
33 }
34 else if($d_int < 720){ //hour in one day 3600*12
35 $this->rustle = floor($d_int/60);
36 $this->unit = 2 ;
37 }
38 else if($d_int < 7200){ //day in ten days 3600*12*10
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 < 4)
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 ?>
javascript是运行在浏览器上的脚本语言,连续多年,被评为全球最受欢迎的编程语言。是前端开发必备三大法器中,最具杀伤力。如果前端开发是降龙十八掌,好么javascript就是第18掌:亢龙有悔。没有它,你的前端生涯是不完整的。《php.cn独孤九贱(3)-JavaScript视频教程》课程特色:php中文网原创幽默段子系列课程,以恶搞,段子为主题风格的php视频教程!轻松的教学风格,简短的教学模式,让同学们在不知不觉中,学会了javascript知识。
JavaScript教程124156次播放
jQuery是一个快速、简洁的JavaScript框架。设计的宗旨是“write Less,Do More”,即倡导写更少的代码,做更多的事情。它封装JavaScript常用的功能代码,提供一种简便的JavaScript设计模式,优化HTML文档操作、事件处理、动画设计和Ajax交互。 核心特性可以总结为:具有独特的链式语法和短小清晰的多功能接口;具有高效灵活的css选择器,并且可对CSS选择器进行扩展;拥有便捷的插件扩展机制和丰富的插件。兼容各种主流浏览器,如IE 6.0+、FF 1.5+、Safari 2.0+、Opera 9.0+等,是全球最流行的前端开发框架之一。PHP中文网根据最新版本,独家录制jQuery最新视频教程,回馈PHP中文网的新老用户。
jQuery教程102646次播放
jQuery是最流行的JS函数库,封装了许多实用的功能,其中最引人入胜的就是Ajax。 jQuery中的Ajax操作,语法简单,操作方便,使Ajax从未如此轻松,前端人员从此不再为与服务器异步交互而发愁,本套课程,精选了最常用的几个方法,从基本的语法到每个参数,再到具体实例进行了全面的讲解。
AJAX教程3988次播放
Git 是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。 Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。 Git 与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不必服务器端软件支持
JavaScript教程3315次播放