存档

作者存档

PHP导出Excel(一)

2010年11月4日 admin 评论已被关闭

PHP导出Excel方法很多,网上也有很多成熟的类,现在用最简单的方法导出一个Excel, 输出一个Table,然后用header 类型改为Excel就可以.

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
<?php
includer_once("config.php");
$sql="select * from user";
$result=mysql_query($sql);
$data_array=mysql_fetch_array($result);
$keynames=array("orderTrade"=>"订单号","orderRecName"=>"收货人姓名","orderCount"=>"数量","orderPhone"=>"电话","orderRecMail"=>"Email","orderRecAddress"=>"地址","orderRecZip"=>"邮编","receiving"=>"收货时间");
function down_xls($data_array,$keynames,$filename) {
   //组合表头行,以制表符\t分隔,并转码为gb18030
   $title = implode("\t", array_values($keynames));
   $title = iconv("UTF-8","GB18030", $title);
 
   $result[] = $title;
  //组合表体行
   foreach ($data_array as $data){
    //按行组合数据体
      $a1 = array();
      foreach ($keynames as $k => $v){
         if ($k == "endtime"){
            $data[$k] = date("Y-m-d H:i", $data[$k]);
         }
         //utf8转码到gb18030,为了windows正常显示
         $a1[] = iconv("UTF-8","GB18030", preg_replace("/[\t]+/"," ",$data[$k]));
      }
      //以制表符分隔每列
      $result[] = implode("\t", $a1);
   }
 
  //为了windows下正常显示,以\r\n为换行符,分隔数据字符串
   $result = implode("\r\n", $result);
   header("Content-type: text/html; charset=GB18030");
   header("Content-Disposition: attachment; filename=\"".$filename.".xls\"");
   exit($result);
} 
down_xls($data_array,$keynames,"dataxls"); 
?>
分类: PHP 标签: , ,

弹窗不止,战斗升级

2010年11月4日 admin 评论已被关闭

一大早上班起来开开电脑,习惯性的打开QQ, 呵,弹窗。


紧接着,360的弹窗也来了。

昨天下午 QQ 决定 在安装360360的客户端上停止运行腾讯的软件。 看来腾讯这次是真怒了,360出的扣扣保镖惹恼了马化腾呀, 不过据说马化腾这次没有动用南山法院,改在北京朝阳法院告的360呀,江湖2个大佬之间的恶战,苦了一帮小屁民呀。

哥继续淡定的观望着。

分类: 网络资源 标签: , , ,

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

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 标签: ,