Posts Tagged ‘php’

安装pear所有包

找到一个文:http://www.karakas-online.de/forum/viewtopic.php?t=1385

内容我翻译了一下:

Question 问题:你需要在本地的php系统中安装所有的pear模块。也许你是一个需要全部模块的开发者。也许在尝试不同的模块,所以一次性的全部安装完是很有必要的,也许你需要查看他们的源代码,也许你需要是不是的安装一个新的pear模块。
一次性的安装和下载所有的pear模块原因很多,但官方并没有给出解决方案。Sad
我搜索了很久都没有发现任何一个单独的tar.gz或者zip包可以一键安装所有的pear模块库。
pear开发者之所有这样做,也许是因为带宽问题、也许他们不想让你的系统加载一些根本不需要的模块。
也或许这样使你像恨perl一样的恨php,因为那永无止境的模块安装。每次你都会热衷于一件事情-运行模块安装脚本。
高兴的是,如果你在linux下面工作:
Arrow解决方案:我假设你运行的php > 4.3.0 , 那么默认pear已经安装。为了一次性下载所有的pear包,你首先得得到一个安装列表:

Code:
pear remote-list | awk ‘{print $1}’ > pear-list

然后手动编辑pear-list,因为你需要手动的删除头两行文字,搞定。
现在输入

Code:
cat pear-list | xargs -n 1 pear install

一些包可能无法安装,需要再运行一次上面的命令:

Code:
cat pear-list | xargs -n 1 pear install

You may not manage to get them all installed (this depends on the versions of your installed components), but you will at least have 99% of them – and that’s enough for the start. Wink
你可能并没有安装完所有的 包(依赖于你安装模块的 版本),但至少至少安装了99%,对起步来说已经够了。
———————-(翻译完)

其实这个方法同样适合安装在windows平台的pear使用 ,windows平台默认没有 xargs awk 这些牛x的工具,这个时候我想到了cygwin。下载安装cygwin,通过awk得到包列表的命令是一样的,假设列表我放在c:\remote-list2 ,pear.bat在D:\phpnow\php-5.2.10-Win32\pear.bat,打开cygwin执行:

cat /cygdrive/c/remote-list2 | xargs -n 1 /cygdrive/d/phpnow/php-5.2.10-Win32/pear.bat install -fa

我发现加上fa两个参数,可以下载更多的包,参数解释:

-f, –force
will overwrite newer installed packages(强制安装)

-a, –alldeps
install all required and optional dependencies(自动安装有被依赖的包)

 

pear安装

如果你需要用php写一个系统,coding from scratch不是很现实,如果你追求效率,那么使用已经写好的php类绝对是不二的选择。我今天就安装了最牛逼玩意儿,pear!

啥是pear呢?

PEAR is short for “PHP Extension and Application Repository” and is pronounced just like the fruit. The purpose of PEAR is to provide:

  • A structured library of open-source code for PHP users
  • A system for code distribution and package maintenance
  • A standard style for code written in PHP, specified here
  • The PHP Extension Community Library (PECL), see more below
  • A web site, mailing lists and download mirrors to support the PHP/PEAR community

简单翻译一下PEAR是“PHP Extension and Application Reporsitory”的简称,也就是php扩展和程序库,发音和fruit一样,PEAR的目标是:

  • 成为php用户开源代码的类库
  • 一个用于包维护和代码分发的系统
  • php代码的一种标准风格
  • php扩展社区酷
  • 支持php/pear社区的一个网站、邮件列表、下载镜像

pear不光是类库,我觉得叫类库仓库比较适合,pear和linux系统上的apt或者yum类似,维护类库以及他们的依赖性。

我的环境是windows 7,php 5.2.10(D:\phpnow\php-5.2.10-Win32目录)

下载安装好php之后,需要手动运行go-pear.bat。

D:\phpnow\php-5.2.10-Win32>go-pear.bat

Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :

选择系统级别安装还是本地安装,默认system,直接回车

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type ‘all’ to change all of them or simply press Enter to
accept these locations.  以下是默认的pear的临时、数据、配置、测试、执行目录的设置,默认回车

1. Installation base ($prefix)                   : D:\phpnow\php-5.2.10-Win32
2. Temporary directory for processing            : D:\phpnow\php-5.2.10-Win32\tmp
3. Temporary directory for downloads             : D:\phpnow\php-5.2.10-Win32\tmp
4. Binaries directory                            : D:\phpnow\php-5.2.10-Win32
5. PHP code directory ($php_dir)                 : D:\phpnow\php-5.2.10-Win32\pea
6. Documentation directory                       : D:\phpnow\php-5.2.10-Win32\doc
7. Data directory                                : D:\phpnow\php-5.2.10-Win32\dat
8. User-modifiable configuration files directory : D:\phpnow\php-5.2.10-Win32\cfg
9. Public Web Files directory                    : D:\phpnow\php-5.2.10-Win32\www
10. Tests directory                               : D:\phpnow\php-5.2.10-Win32\tes
11. Name of configuration file                    : C:\Windows\pear.ini
12. Path to CLI php.exe                           : D:\phpnow\php-5.2.10-Win32\.

1-12, ‘all’ or Enter to continue:
Beginning install…
Configuration written to C:\Windows\pear.ini…(pear配置文件默认写入到这里
Initialized registry…
Preparing to install…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.2.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.2.3.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.7.2.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.2.tar…
pear/PEAR can optionally use package “pear/XML_RPC” (version >= 1.4.0)
install ok: channel://pear.php.net/Archive_Tar-1.3.2
install ok: channel://pear.php.net/Console_Getopt-1.2.3
install ok: channel://pear.php.net/Structures_Graph-1.0.2
install ok: channel://pear.php.net/PEAR-1.7.2
PEAR: Optional feature webinstaller available (PEAR’s web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR’s PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR’s PHP-GTK2-based installer)
PEAR: To install optional features use “pear install pear/PEAR#featurename”

↑然后直接通过默认的channel:pear.php.net 开始直接下载安装pear了,这些包是默认初始化安装的,之后可以添加、删除、更新。

******************************************************************************
WARNING!  The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<D:\phpnow\php-5.2.10-Win32\pear>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.

Current include path           : .;C:\php5\pear
Configured directory           : D:\phpnow\php-5.2.10-Win32\pear
Currently used php.ini (guess) :
Press Enter to continue:

接下来,需要将pear配置目录D:\phpnow\php-5.2.10-Win32\pear加入php.ini的include_path指令中。打开php.ini跳转到include_path,每个路径使用分号分隔,.表示当前目录,所以:

include_path = “.;d:\phpnow\php-5.2.10-Win32\PEAR”

然后重新启动apache,让php.ini的修改生效。

** WARNING! Old version found at D:\phpnow\php-5.2.10-Win32, please remove it or be sure to use the new d:\phpnow\php-5.2.10-win32\pear.bat command

The ‘pear’ command is now at your service at d:\phpnow\php-5.2.10-win32\pear.bat

然后可以通过pear.bat命令来对pear系统进行各种管理。
* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under D:\phpnow\php-5.2.10-Win32\PEAR_ENV.reg .
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.

运行php目录下的PEAR_ENV.reg将PEAR的各种目录加入环境变量中。

接下来需要测试pear时候已经安装成功,新建一个php文件,写入内容:

1
2
equire_once 'System.php';
var_dump(class_exists('System'));

如果页面返回 bool(true) 表明安装成功。

一些常用的pear命令
安装包
  pear install packagename

下载包,但不安装
  pear download packagename
  pear download-all

安装已经下载的包
  pear install filename.tgz

列出channel里面所有的包
  pear remote-list

列出已经安装的包
  pear list

列出可升级的包
  pear list-upgrades

更新包
  pear upgrade packagename
  pear upgrade-all

删除包
  pear uninstall packagename

就大概说到这里,感兴趣的可以转移到官方网站了解详情,下载一个手册也够你看1年的了,囧。

主页:http://pear.php.net/

文档:http://pear.php.net/manual/

bugs:http://pear.php.net/bugs/

 

配置smarty开发环境

首先到 http://www.smarty.net 上下载最新的smarty模板引擎,解压Smarty-2.6.26.zip,改名Smarty-2.6.26目录为smarty。

拷贝smarty目录到你希望的目录 D:\xampp\xampp\smarty。

在php.ini的include_path加入smarty库目录,如下:

include_path = “.;D:\xampp\xampp\php\PEAR;D:\xampp\xampp\smarty\libs”

在你的php项目目录新建两个子目录放配置文件和模板:config 和templates

D:\xampp\xampp\htdocs\config

D:\xampp\xampp\htdocs\templates

smarty项目目录新建两个目录cache和templates_c存放缓存和编译过的模板:

D:\xampp\xampp\smarty\cache

D:\xampp\xampp\smarty\templates_c

在需要调用smarty库的php文件中写入代码:

1
2
3
4
5
6
7
8
9
10
11
//this is D:\xampp\xampp\htdocs\index.php
//load smarty library
require('Smarty.class.php');

$smarty=new Smarty();
$smarty->template_dir='d:/xampp/xampp/htdocs/templates'; //指定模板存放目录
$smarty->config_dir='d:/xampp/xampp/htdocs/config';//指定配置文件目录
$smarty->cache_dir='d:/xampp/xampp/smarty/cache';//指定缓存目录
$smarty->compile_dir='d:/xampp/xampp/smarty/templates_c';//指定编译后的模板目录
$smarty->assign('name','fish boy!');
$smarty->display('index.tpl');

再新建一个D:\xampp\xampp\htdocs\templates\index.tpl文件

1
2
3
4
5
6
7
8
9
10
<html>
<head><title>hello,{$name}!</title>
<script language="javascript" type="text/javascript">
    alert('{$name}');
</script>
</head>
<body>
hello,{$name}!
</body>
</html>

打开http://localhost/index.php 应该会弹出fish boy!警告,然后内容为hello,fish boy!!的页面。
我们可以改进一下,不可能每次需要smarty写这么多配置代码吧。
新建文件 D:\xampp\xampp\htdocs\smarty_connect.php

1
2
3
4
5
6
7
8
9
10
11
//load smarty library
require('Smarty.class.php');
class smarty_connect extends Smarty
{   function smarty_connect()
    {//每次构造自动调用本函数
        $this->template_dir='d:/xampp/xampp/htdocs/templates';
        $this->config_dir='d:/xampp/xampp/htdocs/config';
        $this->cache_dir='d:/xampp/xampp/smarty/cache';
        $this->compile_dir='d:/xampp/xampp/smarty/templates_c';
    }
}

D:\xampp\xampp\htdocs\index.php改为:

1
2
3
4
    require('smarty_connect.php');
    $smt=new smarty_connect;
    $smt->assign('name','fish boy!');
    $smt->display('index.tpl');

index.tpl文件不变,打开localhost/index.php,出现了同样的输出。

 

PHP5 面向对象初步.pdf下载

这个星期把这本书看完了。

phpchina的刀客羽朋写的,有5章,讲的比较有趣,每个例子都有在zend studio下面的运行裁图。

下载地址:

http://4u3w.net/books/down.aspx?id=1049

 

php写的cet成绩批量查询

一直都关注cnbeta的动态,没想到20号的时候登录尽然有这条新闻:‘“2009年6月CET6成绩于今天2009年8月20号早上9点公布” ,cnbeta现在是嘛新闻都出啊。于是乎就拿出了俺的“证件夹”,掏出了准考证开始查成绩,我对这个网上cet查分的网站的认识和评价基本上和此文一样,这次6级得到437分,感觉还是差不多了,因为还重来没有认认真真的停下来背单词、作题,除了考四级的时候作了一张模拟卷。

cet_band_6_result

这个查询网站通过ajax来查询,需要等待15秒的时间,每次限查询一人成绩,听说08年的时候还要安装activex控件才能查询,对于linux用户就恼火了。通过分析一下http://cet.99sushe.com/这个页面发现没有表单(form),而是这样一句:

<input id="btn" type="button" name="" value="查询" onclick="submit_search();" /></p>

调用了一个js函数submit_search(); 网页引用了一个js文件:http://cet.99sushe.com/res/js/cet0908.js

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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var testid = "";
var score = "";
var contenthtml = "";
var sec = 15;  //默认等待15秒钟
String.prototype.trim  =  function(){
return  this.replace(/(^\s*)|(\s*$)/g,  ""); //javascrip没有自带trim函数,用来消除空白符
}
function gid(id) {return document.getElementById(id);} //返回表单输入的准考证号的值
function assertFormat(tid){   //检查准考证号格式
    var reg = /^\d{1,}$/;  //regexp 表示全部为数字
    if (!reg.test(tid) || tid.length != 15 || tid.substr(6, 3) != "091" || get_testtype(tid) == "") { //第6位其的三位数不是091的不准查,意思就是只能查09年上半年的成绩,而后用curl发现根本就没有其他几次考试的数据
    alert("准考证号格式不正确");
    return false;
}
else {
    for (var i = 1; i &lt;= 7; i++) {
        if (gid("t" + i).checked) {
            if (tid.substr(9, 1) != gid("t" + i).value) {
                alert("考试类型和准考证号不匹配");
                return false;
        }
    }
}
}
return true;
}
function submit_search() { //提交查询
    var testid_c = gid("id");
    var c = assertFormat(testid_c.value.trim());
    if(!c) {
        testid_c.focus();
        return;
}
testid = testid_c.value.trim();
if (contenthtml == "") contenthtml = gid("content").innerHTML; //得到content的div的innerHTML
//search(testid);
wait(); //等待15秒
}
function wait(){ //等待的时候把waithtml插入到content的div中
    var sec_all = sec;
    var waithtml = "
    <div id="
score_result">
    <div id="
score_inner">";
    waithtml += "
    <div id="
wait_title">系统正在查询中请稍候</div>
    "
;
    waithtml += "
    <div id="
time">" + sec + "</div>
    "
;
    waithtml += "</div>
    </div>
    "
;
    gid("content").innerHTML = waithtml;
    setTimeout("search(" + testid + ")", 0);
    wait_time(sec_all);
}
function wait_time(waitsec){
    if (waitsec > 0) { //15秒没有到
        gid("time").innerHTML = waitsec;
        waitsec--;
        setTimeout("wait_time(" + waitsec + ")", 1000);   //难道这就是传说的中递归调用函数?!
}
    else{
        showscore(score); //时间到了也该显示分数得了
    }
}
function showscore(tscore){
var name = "";
var school = "";
var sarray=new Array();
if(tscore != ""){
    sarray = tscore.split(',');//根据不同的考试类型来给sarray数列赋值
if (sarray.length >= 7) {
    name = sarray[6];
    school = sarray[5];
}
else {
    name = sarray[2];
    school = sarray[1];
}
}
var resulthtml = "
<div id="
score_result">
<h1>2009年6月考试成绩查询结果:</h1>
<div id="
score_inner">";
resulthtml += " <dl> <dt class="dtleft">考生姓名:</dt> <dd class="ddright">"+name+"</dd>";
resulthtml += "

<dt class="
dtleft">学校:</dt> <dd class="ddright">" + school + "</dd>";
resulthtml += "

<dt class="
dtleft">考试类别:</dt> <dd class="ddright">";
resulthtml += get_testtype(testid);
resulthtml += "</dd> <dt></dt> <dd style="overflow: hidden; height: 0px; clear: both;"></dd>";
resulthtml += "

<dt class="
dtleft">准考证号:</dt> <dd class="ddright">";
resulthtml += testid;
resulthtml += "</dd> </dl>
<ul>"
;
if(tscore == "") resulthtml += "<li>无法找到对应准考证号的分数,请确认你输入的准考证号无误</li>";
else {
if (sarray.length >= 7) {
    resulthtml += "
        <li>
    <div class="
lileft">您的成绩总分:</div>
    <div class="
liright" style="font-weight:bold;">" + sarray[4] + "</div></li>
    "
;
    resulthtml += "
        <li>
    <div class="
lileft">听力:</div>
    <div class="
liright">" + sarray[0] + "</div></li>
    "
;
    resulthtml += "
        <li>
    <div class="
lileft">阅读:</div>
    <div class="
liright">" + sarray[1] + "</div></li>
    "
;
    resulthtml += "
        <li>
    <div class="
lileft">综合:</div>
    <div class="
liright">" + sarray[2] + "</div></li>
    "
;
    resulthtml += "
        <li>
    <div class="
lileft">写作:</div>
    <div class="
liright">" + sarray[3] + "</div></li>
    "
;
}
else {
resulthtml += "
    <li>
<div class="
lileft">您的成绩总分:</div>
<div class="
liright" style="font-weight:bold;">" + sarray[0] + "</div></li>
"
;
}
}
resulthtml += "</ul>
<div style="
text-align:center;">姓名中的生僻字可能无法正常显示,以成绩单为准</div>
</div>
"
;
resulthtml += "
<p class="
lang" style="margin-top:-10px;text-align:center;"><input id="btn" onclick="re_search();" type="button" value="返回" /></p>

"
;
resulthtml += "</div>
"
;
gid("content").innerHTML = resulthtml; //通过js写html到dom上,用IE,firefox默认的源代码查看工具都没有发现源代码的变化,但是firefox扩展firebug就能看到,看来还是firebug牛逼。
}
function re_search() { //清空数据
        var testid = "";
        var score = "";
        gid("content").innerHTML = contenthtml;
}

function get_testtype(tid) { //根据考号得到考试类型
    switch (tid.substr(9, 1)) {
        case "1": return "英语四级";
        case "2": return "英语六级";
        case "3": return "日语四级";
        case "4": return "日语六级";
        case "5": return "德语四级";
        case "7": return "俄语四级";
        case "9": return "法语四级";
        default: return "";
    }
}
function search(tid){ //通过ajax post数据"id="+xxxxxxxxxxxxxxx
        var ajax = new Ajax();
        ajax.Post("/getscore.html", "id="+tid, search_callback); //这个就是关键,通过post发送数据到getscore.html来完成查询。
}
function search_callback(success, responsetext) {
    if (success) {
            score = responsetext;
            //showscore(score);
    }
    else {
        search(testid);
    }
}

——————————————-

总结起来就是向getscore.html post一个数据”id=”+xxxxxxxxxxxx

可以通过curl向指定的服务器发送数据包,具体方法此文 “斗智斗勇续 四六级查分技巧 ” 有介绍,需要注意的一点是查询的服务器有referer验证,referer验证一般用来防盗链,防止数据从非本站的提交上去,不过自定义referer并不是什么好难的事情,此为的作者还做了一个c#的gui前端,基本上就是把cmd的输出放在gui界面上,没有多大的意义。这个 “CET在线连续查分程序” 是别人用c#弄的一个在线查询,可以指定准考证号的起始号码和结束号码,就可以连续查询了。

然后我受到这样的启发,做了一个php版本的,演示地址:http://tunpishuang.iamspace.com/cet.php , 和c#那个略有不同的是并不是指定起始和结束地址,而是直接输入前6位,最多输出6000人的成绩,我贴一下源代码:

cet.php —————————————————

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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>2009年上半年CET院校成绩批量查询 by tunpishuang</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
#description{
    border:solid 4px 4px 10px 4px #828282;
    color:#8B0000;
    width:420px;
}
#form{
    border:solid 4px #828282;
    color:#8B0000;
    width:520px;
}
</style>
</head>
<body>
<h1>2009年上半年CET院校成绩批量查询 by tunpishuang</h1>
<div id="description">
A.前6位是地区号.(可以问与你同一城市报名的任何一人)<br />
B.然后是071 (表示07年的第1次,即07年6月份的)<br />
C.然后是1或2 (1代表四级,2代表6级)<br />
D.然后的三位是你的考场号,多为0**或1**<br />
E.最后两位是你的座位<br />
</div>
<form method="post" action="cet_query.php">
<div id="form">
单人成绩查询(输入准考证号)<input type="text" name="tid" id="tid" size="15" maxlength="15" /><input type="submit" value="查一查,更健康" /><p></p>
院校成绩查询(输入准考证号前六位)<input type="text" name="cid" id="cid" size="8" maxlength="6" /><input type="submit" value="查一查,更健康" />
</div>
</form>
<div>
<h1>这个查询程序草草完工,有待完善的地方,但是我不想弄了,弄老一天,人都矿鸟<p></p>
有空到我博客来耍哈,<a href="http://techguru.cn">http://techguru.cn</a></h1>
</div>
</body>
</html>

cet_query.php—————————————————-

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
<?php
echo "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title>查询结果</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />
<style type=\"text/css\">
table,td,tr,th{
    border:solid 1px #1E90FF;
    text-align:center;
}
</style>
</head>
<body>
<table cellpadding=\"15\" cellspacing=\"0\" >
<tr>
    <th>听力</th>
    <th>阅读</th>
    <th>综合</th>
    <th>写作</th>
    <th>总分</th>
    <th>学校</th>
    <th>姓名</th>
</tr>
"
;

$data_fmt=array();
function query($id){
    $curl = curl_init();
    $curlpost='id='.$id;
    curl_setopt($curl, CURLOPT_URL, 'http://cet.99sushe.com/getscore.html');
    curl_setopt($curl, CURLOPT_REFERER, 'http://cet.99sushe.com');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POST,1);
    curl_setopt($curl, CURLOPT_POSTFIELDS,$curlpost);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT,0);
    $data = curl_exec($curl);
    global $data_fmt;
    $data_fmt=explode(",",$data);
    echo "
<tr>
    <td>$data_fmt[0]</td>
    <td>$data_fmt[1]</td>
    <td>$data_fmt[2]</td>
    <td>$data_fmt[3]</td>
    <td>$data_fmt[4]</td>
    <td>$data_fmt[5]</td>
    <td>$data_fmt[6]</td>
</tr>"

;
    curl_close($curl);
    }

function person_query($tid){
    query($tid);
   
}
function college_query($cid)
{   $cid=$_POST['cid'];
    $cid=sprintf("%.0f",$cid."091200100");
    $j=0;
    $k=0;
    while($k<2){
            while($j<100){
                    for($i=0;$i<30;$i++)
                        {   $cid=sprintf("%.0f",$cid+1);
                            query($cid);
                        }
                    $cid=$cid-30;
                    $cid=$cid+100;
                    $j++;
            }
        $cid=$_POST['cid'];
        $cid=sprintf("%.0f",$cid."091200100");
        $j=0;
        $k++;
       
    }
}
if(($_POST['tid'])!=0){
    $tid=$_POST['tid'];
    person_query($tid);
    }
if(($_POST['cid'])!=0){
    $cid=$_POST['cid'];
    college_query($_POST['cid']);
    }
echo "</table>
</body>
</html>"
;
?>
<!--  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>查询结果</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
table,td,tr,th{
    border:solid 1px #1E90FF;
    text-align:center;
}
</style>
</head>
<body>
<table cellpadding="15" cellspacing="0" >
<tr>
    <th>听力</th>
    <th>阅读</th>
    <th>综合</th>
    <th>写作</th>
    <th>总分</th>
    <th>学校</th>
    <th>姓名</th>
</tr>

<tr>
    <td><?php echo $data_fmt[0]?></td>
    <td><?php echo $data_fmt[1]?></td>
    <td><?php echo $data_fmt[2]?></td>
    <td><?php echo $data_fmt[3]?></td>
    <td><?php echo $data_fmt[4]?></td>
    <td><?php echo $data_fmt[5]?></td>
    <td><?php echo $data_fmt[6]?></td>
</tr>
</table>
</body>
</html>
-->

没有什么好讲的吧,主要是用到了php的libcurl库抓网页。