Snoopy中文手册(毛毛虫翻译)

Filed under: Spider | 3 Comments »
Posted on
  1. /**
  2. * @name Snoopy手册中文版
  3. * @author 毛毛虫 wangchong1985@gmail.com
  4. * @version Snoopy - the PHP net client v1.2.2
  5. * @link http://www.wangchong.org
  6. * @since 2008-04-27
  7. */

名称:

Snoopy - the PHP net client v1.2.2

概要:

  1. include "Snoopy.class.php";
  2.     $snoopy = new Snoopy;
  3.    
  4.     $snoopy->fetchtext("http://www.php.net/");
  5.     print $snoopy->results;
  6.    
  7.     $snoopy->fetchlinks("http://www.phpbuilder.com/");
  8.     print $snoopy->results;
  9.    
  10.     $submit_url = "http://lnk.ispi.net/texis/scripts/msearch/netsearch.html";
  11.    
  12.     $submit_vars["q"] = "amiga";
  13.     $submit_vars["submit"] = "Search!";
  14.     $submit_vars["searchhost"] = "Altavista";
  15.        
  16.     $snoopy->submit($submit_url,$submit_vars);
  17.     print $snoopy->results;
  18.    
  19.     $snoopy->maxframes=5;
  20.     $snoopy->fetch("http://www.ispi.net/");
  21.     echo "<PRE>\n";
  22.     echo htmlentities($snoopy->results[0]);
  23.     echo htmlentities($snoopy->results[1]);
  24.     echo htmlentities($snoopy->results[2]);
  25.     echo "</PRE>\n";
  26.  
  27.     $snoopy->fetchform("http://www.altavista.com");
  28.     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 »

仿QQ等级显示函数

Filed under: PHP&MySQL | No Comments »
Posted on

开头先引述下QQ等级的算法:
设当前等级为N,达到当前等级最少需要的活跃天数为D,当前活跃天数为Dc,升级剩余天数为Dr,则:

mimetex.gif

从而推出:

mimetex1.gif

好了,引述完成,懒得写字了,贴出代码:

  1. <?php
  2. /**
  3. *
  4. * showRank.php
  5. * QQ等级输出类库
  6. * @author 毛毛虫 <wangchong1985@gmail.com>
  7. * @version 1.0 2008-04-09
  8. *
  9. */
  10. class showRank {
  11.    
  12.     /**
  13.      * 第一级图片显示字段
  14.      */
  15.     public $mImage1;
  16.    
  17.     /**
  18.      * 第二级图片显示字段
  19.      */
  20.     public $mImage2;
  21.    
  22.     /**
  23.      * 第三级图片显示字段
  24.      */
  25.     public $mImage3;
  26.  
  27.     /**
  28.      * 构造函数:传入图片值
  29.      * @return
  30.      */
  31.     function __construct($pImage1 = '',$pImage2 = '',$pImage3 = '') {
  32.         $this->mImage1 = $pImage1;
  33.         $this->mImage2 = $pImage2;
  34.         $this->mImage3 = $pImage3;
  35.     }
  36.    
  37.     /**
  38.      * 根据活跃天数计算用户等级。(模仿QQ的升级方式)
  39.      * @return int
  40.      * @access public
  41.      */
  42.     function get_rank($pScore) {
  43.         $temp = $pScore+4;
  44.         $tRank = sqrt($temp)-2;
  45.         $tRank = floor($tRank);
  46.         return $tRank;
  47.     }
  48.    
  49.     /**
  50.      * 用户等级标志,根据用户等级显示用户标志
  51.      * 仿照QQ等级的四进制显示
  52.      * @return str
  53.      * @access public
  54.      */
  55.     function get_score($pScore) {
  56.         $str = '';
  57.         $tRank = $this->get_rank($pScore);//根据分数取得等级
  58.         $tPicNum = base_convert($tRank,10,4);//转化为四进制
  59.         $tPicNum = strrev($tPicNum);//翻转字符串
  60.         $tArray = str_split($tPicNum);//转化为数组
  61.         $tNum = count($tArray);
  62.         if($tNum<=3) {
  63.             for($i=$tNum-1;$i>=0;$i--){
  64.                 switch($i){
  65.                     case '0':
  66.                         for($j=0;$j<$tArray[$i];$j++){
  67.                             $str .= $this->mImage1;
  68.                         }
  69.                     break;
  70.                     case '1':
  71.                         for($j=0;$j<$tArray[$i];$j++){
  72.                             $str .= $this->mImage2;
  73.                         }
  74.                     break;
  75.                     case '2':
  76.                         for($j=0;$j<$tArray[$i];$j++){
  77.                             $str .= $this->mImage3;
  78.                         }
  79.                     break;
  80.                     default:
  81.                         //$str = ;
  82.                     break;
  83.                 }
  84.             }
  85.         }else {
  86.             $str =     $this->mImage3.$this->mImage3.$this->mImage3.$this->mImage3;
  87.         }
  88.         return $str;
  89.  
  90.     }
  91.  
  92. }
  93. ?>

Read the rest of this entry »