将文字表述的时间 转化为相应的时间

2010年11月3日 admin 没有评论
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
     /*
	 *将文字表述的时间 转化为相应的时间
	*/
	function changToDateTime($str)
	{
		$str=trim($str);
		$res=array();
		//如果本身是时间格式
		if(preg_match("/(\d{4}-\d{1,2}-\d{1,2})\s(\d{1,2}:\d{1,2}:\d{1,2})/",$str)){
			$res=explode(" ",$str);
			$res[2]=$str;
		}elseif(preg_match('/(\d{4})年(\d{1,2})月(\d{1,2})日\s(\d{1,2}:\d{1,2})/',$str,$match)){
			$res[0]=$match[1].'-'.$match[2].'-'.$match[3];
			$res[1]=$match[4].':00';
			$res[2]=$res[0].' '.$res[1];			
		}elseif(preg_match('/(\d{1,2})月(\d{1,2})日\s(\d{1,2}:\d{1,2})/',$str,$match)){
			$res[0]=date("Y").'-'.$match[1].'-'.$match[2];
			$res[1]=$match[3].':00';
			$res[2]=$res[0].' '.$res[1];			
		}elseif(preg_match('/(\d{4})\s*年(\d{1,2})\s*月(\d{1,2})\s*日/',$str,$match)){
			//只有日期数据的格式
			$res[0]=$match[1].'-'.$match[2].'-'.$match[3];
			$res[1]='00:00:00';
			$res[2]=$res[0].' '.$res[1];	
		}elseif(preg_match("/(\d+)\s*秒前/",$str,$match)){
			$dateTime=time()-$match[1];
			$dateTime=date("Y-m-d H:i:s",$dateTime);
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;			
		}elseif(preg_match("/(\d+)\s*分钟前/",$str,$match)){//如果是分钟格式 如:3分钟前
			$dateTime=time()-$match[1]*60;
			$dateTime=date("Y-m-d H:i:s",$dateTime);
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match("/(\d+)\s*小时前/",$str,$match)){//如果是小时格式
			$dateTime=time()-$match[1]*3600;
			$dateTime=date("Y-m-d H:i:s",$dateTime);
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match("/(\d+)\s*天前/",$str,$match)){
			$dateTime=time()-$match[1]*3600*24;
			$dateTime=date("Y-m-d H:i:s",$dateTime);
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match("/(\d+)\s*[h|H]ours/",$str,$match)){
			//英文版本的多少个小时以前
			$dateTime=time()-$match[1]*60;
			$dateTime=date("Y-m-d H:i:s",$dateTime);
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match("/([a-zA-Z])+\s+(\d{1,2}):(\d{1,2}:\d{1,2})\s+[A|P]M/",$str,$match)){
			//英文版本带昨天 之类 的说明 
			if($match[1]=='Yesterday'){
				$res[0]=date("Y-m-d",time()-86400);
			}else{
				$res[0]=date("Y-m-d"); //默认设置为今天 会出错!!根据 实际 情况 完善
			}
			//如果 是下等,时间要加12个小时
			if($match[4]=='PM'){
				$match[2]=intval($match[2]); //应该是去年前面 的0! 待改
				$match[2]+=12;
			}
			$res[1]=$match[2].":".$match[3];			
			$res[2]=$res[0]." ".$res[1];
		}elseif(preg_match("/\d{1,2}\/\d{1,2}\/10/",$str,$match)){
			$res[0]="2010-".$match[1]."-".$match[2];
			$res[1]="00:00:00"; 
			$res[2]=$res[0]." ".$res[1];
		}elseif(preg_match('/(\d+)\s*[M|m]inutes/',$str,$match)){
			$dateTime=time()-$match[1]*60;
			$dateTime=date("Y-m-d H:i:s",$dateTime);
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match('/前天 (\d{1,2}:\d{1,2})/',$str,$match)){
			$dateTime=time()-24*60*60*2;
			$dateTime=date("Y-m-d",$dateTime).' '.$match[1].':00';
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match('/昨天 (\d{1,2}:\d{1,2})/',$str,$match)){
			$dateTime=time()-24*60*60;
			$dateTime=date("Y-m-d",$dateTime).' '.$match[1].':00';
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match('/今天 (\d{1,2}:\d{1,2})/',$str,$match)){
			$dateTime=date("Y-m-d").' '.$match[1].':00';
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match('/(\d{1,2}-\d{1,2}) (\d{1,2}:\d{1,2})/',$str,$match)){
			$dateTime=date("Y").'-'.$match[1].' '.$match[2].':00';
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match('/(\d{2,4}-\d{1,2}-\d{1,2}) (\d{1,2}:\d{1,2})/',$str,$match)){
			$dateTime=$match[1].' '.$match[2].':00';
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match('/(\d+)\s*Seconds/',$str,$match)){
			$dateTime=time()-$match[1];
			$dateTime=date("Y-m-d H:i:s",$dateTime);
			$res=explode(" ",$dateTime);
			$res[2]=$dateTime;
		}elseif(preg_match('/([a-zA-Z]+)\s+(\d+).*?(\d{4})/',$str,$match)){
			//格式:Mar 1,2010
			$m=$this->monthSimple($match[1]);
			$res[0]=$match[3].'-'.$m.'-'.$match[2];
			$res[1]="00:00:00";
			$res[2]=$res[0]." ".$res[1];
		}elseif($str=='今天'){
			$res[0]=date("Y-m-d");
			$res[1]="00:00:00";
			$res[2]=$res[0]." ".$res[1];
		}elseif($str=='昨天') {
			$dateTime=time()-86400;
			$res[0]=date("Y-m-d",$dateTime);
			$res[1]="00:00:00";
			$res[2]=$res[0]." ".$res[1];
		}elseif($str=='前天'){
			$res[0]=date("Y-m-d",(time()-86400*2));
			$res[1]="00:00:00";
			$res[2]=$res[0]." ".$res[1];
		}elseif($str=='刚刚'){
			$res[0]=date("Y-m-d");
			$res[1]=date("H:i:s");
			$res[2]=$res[0]." ".$res[1];
		}else{ 
			$res[0]="0000-00-00";
			$res[1]="00:00:00";
			$res[2]=$res[0]." ".$res[1];
		}
		return $res;
	}
分类: PHP 标签: ,

看着舒服的颜色

2010年10月31日 admin 没有评论

Tips:You can change the code before run.

分类: WEB标准 标签: ,

jQuery性能优化

2010年10月31日 admin 1 条评论

现在jquery应用的越来越多, 有些同学在享受爽快淋漓coding时就将性能问题忽略了, 比如我. jquery虽在诸多的js类库中性能表现还算优秀, 但毕竟不是在用原生的javascript开发, 性能问题还是需要引起重视的.
1,总是从ID选择器开始继承

在jQuery中最快的选择器是ID选择器,因为它直接来自于JavaScript的getElementById()方法。

例如有一段HTML代码:

<div id="content">
<form method="post" action="#">
<h2>交通信号灯</h2>
<ul id="traffic_light">
<li><input type="radio" class="on" name="light" value="red" /> 红色</li>
<li><input type="radio" class="off" name="light" value="yellow" /> 黄色</li>
<li><input type="radio" class="off" name="light" value="green" /> 绿色</li>
</ul>
<input class="button" id="traffic_button" type="submit" value="Go" />
</form>
</div>

阅读全文…

分类: AJAX 标签: ,

Windows下SVN的配置详解

2010年10月29日 admin 没有评论

Subversion,简称SVN,是一个开放源代码的版本控制系统。 额. 灰常好用。

准备工作 :
下载:
服务器端程序下载: http://subversion.tigris.org/getting.html#binary-packages

Windows常用客户端TortoiseSVN:http://tortoisesvn.net/downloads

好了。win下 傻瓜式 下一步下一步安装完毕(装完客户端需要重启)。 现在做一下配置一个版本库。

1:创建一个版本库 ,可以在任意一个盘里 右键–选择创建

阅读全文…

分类: PHP 标签: , , ,

加强版珊瑚虫归来 —360扣扣保镖

2010年10月29日 admin 没有评论

随着昨天360与腾讯公司的’战斗升级’(腾讯联合百度等5家公司集体抵制360), 今天360公司在北京宣布,推出一款新软件—“360扣扣保镖” .
试用了一下,简直就是加强版的珊瑚虫QQ (不带显IP的) , 不知道 马化腾 下一步该如何对付,会不会 南山法院见。 中国的互联网过一段时间就会有点新闻,已经见怪不怪了, 可是中国的互联网技术却永远超不过外国的技术,总是在山寨国外。是中国人没创造力吗? 笑笑…在天朝,一切都是浮云….


阅读全文…

PHP fsockopen 函数

2010年10月28日 admin 没有评论

Description
resource fsockopen ( string target [, int port [, int &errno [, string &errstr [, float timeout]]]] )

Initiates a socket connection to the resource specified by target. PHP supports targets in the Internet and Unix domains as described in 附录 N. A list of supported transports can also be retrieved using stream_get_transports().

注: If you need to set a timeout for reading/writing data over the socket, use stream_set_timeout(), as the timeout parameter to fsockopen() only applies while connecting the socket.

As of PHP 4.3.0, if you have compiled in OpenSSL support, you may prefix the hostname with either ‘ssl://’ or ‘tls://’ to use an SSL or TLS client connection over TCP/IP to connect to the remote host.

fsockopen() returns a file pointer which may be used together with the other file functions (such as fgets(), fgetss(), fwrite(), fclose(), and feof()).

If the call fails, it will return FALSE and if the optional errno and errstr arguments are present they will be set to indicate the actual system level error that occurred in the system-level connect() call. If the value returned in errno is 0 and the function returned FALSE, it is an indication that the error occurred before the connect() call. This is most likely due to a problem initializing the socket. Note that the errno and errstr arguments will always be passed by reference.

Depending on the environment, the Unix domain or the optional connect timeout may not be available.

The socket will by default be opened in blocking mode. You can switch it to non-blocking mode by using stream_set_blocking().

打开网络的 Socket 链接。
语法: int fsockopen(string hostname, int port, int [errno], string [errstr], int [timeout]);
返回值: 整数
函数种类: 网络系统

内容说明目前这个函数提供二个 Socket 资料流界面,分别为 Internet 用的 AF_INET 及 Unix 用的 AF_UNIX。当在 Internet 情形下使用时,参数 hostname 及 port 分别代表网址及埠号。在 UNIX 情形可做 IPC,hostname 参数表示到 socket 的路径,port 配置为 0。可省略的 timeout 选项表示多久没有连上就中断。在使用本函数之后会返回文件指针,供文件函数使用,包括 fgets()、fgetss()、fputs()、fclose() 与 feof()。参数 errno 及 errstr 也是可省略的,主要当做错误处理使用。使用本函数,会使用搁置模式 (blocking mode) 处理,可用 set_socket_blocking() 转换成无搁置模式。

使用范例
本例用来模拟成HTTP连接。

<?php
$fp = fsockopen("www.wenan8.com", 80, &$errno, &$errstr, 10);
if(!$fp) {
        echo "$errstr ($errno)<br>\n";
} else {
        fputs($fp,"GET / HTTP/1.0\nHost: www.wenan8.com\n\n");
        while(!feof($fp)) {
                echo fgets($fp,128);
        }
        fclose($fp);
}
?>
分类: PHP 标签: ,

定时运行PHP页面

2010年10月28日 admin 没有评论

某个PHP页面需要在每天的某个时间定时运行。
其实就是应用windows的定时任务。
控制面板中任务计划–》添加任务计划–》 依次下一步找到php的安装目录php.exe 然后 高级设置里 -q 命令 运行某个页面。(如图)

分类: PHP 标签: , ,

PHP模拟浏览器重启路由器

2010年10月28日 admin 没有评论

项目中需要用到经常采集搜索引擎的数据,而百度,google等对短时间内大流量搜索做了限制,会限制IP(百度) 等,google的更是做了识别本机生成cookie(猜测) 的限制,模拟cookie都不行。

大多数采集器都做了自动重启IP的功能, 当采集页面匹配到做了限制的 正则时,执行重启IP:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//$this->noData 为匹配限制的页面正则, $this->page 为页面内容,可用file_get_content()获取
 
if(preg_match($this->noData,$this->page)){
$this->reStartRouter();
 
}
 
//操作路由
 
function router($target=''")
 
{
 
$server  = '192.168.0.1';            // IP address
 
$host    = '192.168.0.1';            // Domain name
 
$port    = 80;
 
$referer = 'http://'.$host.$target;    // Referer
 
$username = "admin";#路由的用户名
 
$password = "admin";#路由的管理密码
 
$authorization = base64_encode($username.":".$password);
 
$File = fsockopen($server, $port, $errno, $errstr, 50);
 
if ($File)
 
{
 
$out = "GET $target HTTP/1.1\r\n";
 
$out .= "Host: $host\r\n";
 
$out .= "Referer: $referer\r\n";
 
$out .= "Authorization: Basic $authorization\r\n";
 
$out .= "Connection: Close\r\n\r\n";
 
fputs($File, $out);
 
$makeFile = $buffer = "";
 
while ($buffer = fread($File,4096))
 
{
 
$makeFile = $makeFile.$buffer;
 
}
 
fclose($File);
 
return $makeFile;
 
}
 
}
 
//断开
 
function disconnectr() {
 
$url = '/if.cgi?redirect=sys_status.htm&amp;failure=fail.htm&amp;type=wan_state_reset&amp;ifname=ppp0&amp;ifstatus=Up&amp;ifcmd=DISCONNECT';
 
router($url);
 
}
 
//连接
 
function connectr() {
 
$url = '/if.cgi?redirect=sys_status.htm&amp;failure=fail.htm&amp;type=wan_state_reset&amp;ifname=ppp0&amp;ifstatus=Down&amp;ifcmd=CONNECT';
 
router($url);
 
}
 
function reStartRouter()
{
$r=new router();
$r->disconnectr();//断开
$r->connectr();//连接
sleep(3);//静止3秒,一般要过一会才可以 连上
return true;
}
分类: PHP 标签: ,

Twitter新搜索架构将采用开源Lucene

2010年10月11日 admin 没有评论

除了重新设计了UI,在后端,Twitter也带来了非常巨大的变化。今天,Michael Busch 更新了Twitter Engineering Blog, 给我们带来了一些搜索方面改进的细节。

刚开始Twitter的实时搜索引擎是基于Summize技术,Summize是Twitter 于 2008 年收购的一家公司。但是从那以后,Twitter开始显著成长:每秒 1000 条推和 12000 个查询,一天下来要 10 亿查询,从那里起,Twitter 的工程师团队就开始寻找一个替代品了,因为旧式的基于MySQL的系统已经面临了巨大的挑战。

所以Twitter开始转向一个新的搜索架构,选择了开源的Lucene。

先不说Lucene的优势,首先它在实时搜索方面就有一些缺点,所以 Twitter 重写了它的部分架构,但是仍然支持 Lucene 的API。重写的部分包括:

* 改进无用数据收集的性能

* 无锁数据结构和算法

* 逆序遍历 posting 列表

* 有效的早期查询终止

Twitter的目标是,信息发布10秒内即可被搜索服务索引。Twitter称,该公司目前只利用了新搜索服务后台约5%的资源,每秒能够索引的Twitter消息数量可以达到当前的50倍。使工程师们”至少支持更大负载“的使命向前迈进了一步。

值得注意的是,就在一个月前,Google曾发布了Instant即时搜索功能,并向美国用户正式推出,当用户在谷歌搜索框中输入“W”时,谷歌便可以为其提供当地的天气预报。如果用户最终并未使用“weather”(天气),而是选择了其他关键词,搜索结果页面也会即时刷新,并进行相应的改变。

在Google的Instant即时搜索引擎中,部署了新的缓存系统,用以处理高速度的查询要求,同时连续性地抓取网络内容,并为这些内容重新建立索引。

对于即时搜索技术的未来,我们很难判定谁能代表未来,但不可否认的是,在面向社会化网络时,以Twitter的Lucene架构和Google的Instant技术将是代表未来搜索引擎的重要技术方向。

分类: PHP 标签:

SEO与HTML

2010年9月29日 admin 没有评论
1、<!--页面注解-->
2、<html>
3、<head>
4、<title>页面标题</title>
5、<meta http-equiv=Content-Language content=zh-cn>
6、</meta><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
7、</meta><meta name="keywords" content="关键词">
8、</meta><meta name="description" content="网站描述">
9、<link href="inc/css.css" type="text/css" rel="stylesheet">
10、</link></meta></head>
11、<body>
12、<div>
13、<h1>页面内容标题</h1>
14、<h2>页面相关性标题</h2>
15、<h3>标题系列</h3>
16、<h4>标题系列</h4>
17、<h5>标题系列</h5>
18、<h6>标题系列</h6>
19、<img src="xxx.jpg" alt="图片说明"/>
20、<a href="/" title="链接说明">链接词</a>
21、<strong>重点关键词强调</strong>
22、<b>关键词强调</b><u>关键词强调</u><i>关键词强调</i>
23、</div>
25、<div>
26、版权部分关键词强调
27、</div>
28、</body>
29、</html>

********************************************************

注:在..标签区中的罗列,都是一些基础的HTML标签,这些标签出现的次序是可以变化的。

下面来给大家详细解答一下。
阅读全文…

分类: PHP 标签: ,