Filed under: Spider | 3 Comments »
Posted on 04月 27th, 2008 由 毛毛虫
- /**
- * @name Snoopy手册中文版
- * @author 毛毛虫 wangchong1985@gmail.com
- * @version Snoopy - the PHP net client v1.2.2
- * @link http://www.wangchong.org
- * @since 2008-04-27
- */
名称:
Snoopy - the PHP net client v1.2.2
概要:
- include "Snoopy.class.php";
- $snoopy = new Snoopy;
- $snoopy->fetchtext("http://www.php.net/");
- print $snoopy->results;
- $snoopy->fetchlinks("http://www.phpbuilder.com/");
- print $snoopy->results;
- $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html";
- $submit_vars["q"] = "amiga";
- $submit_vars["submit"] = "Search!";
- $submit_vars["searchhost"] = "Altavista";
- $snoopy->submit($submit_url,$submit_vars);
- print $snoopy->results;
- $snoopy->maxframes=5;
- $snoopy->fetch("http://www.ispi.net/");
- echo "<PRE>\n";
- echo htmlentities($snoopy->results[0]);
- echo htmlentities($snoopy->results[1]);
- echo htmlentities($snoopy->results[2]);
- echo "</PRE>\n";
- $snoopy->fetchform("http://www.altavista.com");
- print $snoopy->results;
描述:
Snoopy是什么?
Snoopy是一个php类,用来模仿web浏览器的功能,它能完成获取网页内容和发送表单的任务。
Snoopy的一些特点:
* 方便抓取网页的内容
* 方便抓取网页的文本内容 (去除HTML标签)
* 方便抓取网页的链接
* 支持代理主机
* 支持基本的用户名/密码验证
* 支持设置 user_agent, referer(来路), cookies 和 header content(头文件)
* 支持浏览器转向,并能控制转向深度
* 能把网页中的链接扩展成高质量的url(默认)
* 方便提交数据并且获取返回值
* 支持跟踪HTML框架(v0.92增加)
* 支持再转向的时候传递cookies (v0.92增加)
Read the rest of this entry »
Filed under: PHP&MySQL | No Comments »
Posted on 04月 11th, 2008 由 毛毛虫
开头先引述下QQ等级的算法:
设当前等级为N,达到当前等级最少需要的活跃天数为D,当前活跃天数为Dc,升级剩余天数为Dr,则:

从而推出:

好了,引述完成,懒得写字了,贴出代码:
- <?php
- /**
- *
- * showRank.php
- * QQ等级输出类库
- * @author 毛毛虫 <wangchong1985@gmail.com>
- * @version 1.0 2008-04-09
- *
- */
- class showRank {
- /**
- * 第一级图片显示字段
- */
- public $mImage1;
- /**
- * 第二级图片显示字段
- */
- public $mImage2;
- /**
- * 第三级图片显示字段
- */
- public $mImage3;
- /**
- * 构造函数:传入图片值
- * @return 无
- */
- function __construct($pImage1 = '★',$pImage2 = '▲',$pImage3 = '●') {
- $this->mImage1 = $pImage1;
- $this->mImage2 = $pImage2;
- $this->mImage3 = $pImage3;
- }
- /**
- * 根据活跃天数计算用户等级。(模仿QQ的升级方式)
- * @return int
- * @access public
- */
- function get_rank($pScore) {
- $temp = $pScore+4;
- $tRank = sqrt($temp)-2;
- $tRank = floor($tRank);
- return $tRank;
- }
- /**
- * 用户等级标志,根据用户等级显示用户标志
- * 仿照QQ等级的四进制显示
- * @return str
- * @access public
- */
- function get_score($pScore) {
- $str = '';
- $tRank = $this->get_rank($pScore);//根据分数取得等级
- $tPicNum = base_convert($tRank,10,4);//转化为四进制
- $tPicNum = strrev($tPicNum);//翻转字符串
- $tArray = str_split($tPicNum);//转化为数组
- $tNum = count($tArray);
- if($tNum<=3) {
- for($i=$tNum-1;$i>=0;$i--){
- switch($i){
- case '0':
- for($j=0;$j<$tArray[$i];$j++){
- $str .= $this->mImage1;
- }
- break;
- case '1':
- for($j=0;$j<$tArray[$i];$j++){
- $str .= $this->mImage2;
- }
- break;
- case '2':
- for($j=0;$j<$tArray[$i];$j++){
- $str .= $this->mImage3;
- }
- break;
- default:
- //$str = ;
- break;
- }
- }
- }else {
- $str = $this->mImage3.$this->mImage3.$this->mImage3.$this->mImage3;
- }
- return $str;
- }
- }
- ?>
