中文编码范围,中文汉字的正则也许用的着。
双字节字符编码范围:
1. GBK (GB2312/GB18030)
\x00-\xff GBK双字节编码范围
\x20-\x7f ASCII
\xa1-\xff 中文gb2312
\x80-\xff 中文 gbk
2. UTF-8 (Unicode)
\u4e00-\u9fa5 (中文)
\x3130-\x318F (韩文)
\xAC00-\xD7A3 (韩文)
\u0800-\u4e00 (日文)
- /**
- * 删除指定目录
- *
- * @param string $dirname 路径
- * @return void
- */
- function rmdir_rf($dirname) {
- if ($dirHandle = opendir($dirname)) {
- chdir($dirname);
- //该处很多地方都写$file = readdir($dirHandle)),当$file = 0时,函数失效
- while (false !== ($file = readdir($dirHandle))) {
- if ($file == '.' || $file == '..') continue;
- if (is_dir($file))rmdir_rf($file);
- else unlink($file);
- }
- chdir('..');
- rmdir($dirname);
- closedir($dirHandle);
- }
- }
该函数在PHP手册中有人写过,但当while语句中的遍历写的有点小问题,在使用中发现函数失效,就随后记下来吧,好像一年多没更新过博客了,惭愧……
- /**
- * @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 »
开头先引述下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;
- }
- }
- ?>
最近一直在做自己的图书站,分别使用过杰奇和读吧两套不同的系统,对于这两套系统也是又爱又恨,爱的是他们的功能强大,恨他们都同属没有开源精神的产物。呵呵,作为一名穷程序员,俺可以理解作者的苦衷,这里就不批判了。
年假期间,无事可做,翻看自己以前的采集代码,发现很多可以优化和提升的地方,就简单做了下优化,其中也使用了用户体验更加优秀的服务器推技术,这里简单的介绍下核心的函数:flush。
Read the rest of this entry »
