|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
对于PHP的语法结构,刚开始真的很不习惯,真搞不懂为什么每个变量之前都要加个“$”符号,每个语句写完之后都必须加上“分号”来表示此句已经结束,还有,PHP对字母的大小写是敏感的,写的时候一定要注意大小写的区别。汉字|转换 秋水无恨 GBK Unicode UTF8 汉字 转换
php的汉字转换一向是对照费事的事
该类内置了四个过滤"&#[dec];","&#x[hex];","%u[hex]","utf8转换"
便利用户的利用,同时也可自界说过滤停止本人喜好的操作
qswhU.php 从这里下载
http://www.blueidea.com/user/qswh/qswhU.zip
class qswhU{
var $qswhData;
function qswhU($filename="qswhU.php"){
$this->qswhData=file($filename);
}
function decode($str,$pattern=0){
$arr=array("/&#(\w+);/iU","/((%\w\w)+)/i","/%u(\w{4,5})/iU");
if(is_integer($pattern)){
if($pattern>=count($arr))die("Invalid Function");
$pattern=$arr[$pattern];
}
return preg_replace_callback($pattern,array($this,"u2gb"),$str);
}
function u2gb($arr){
/******(qiushuiwuhen 2002-8-15)******/
$ret="";$str=$arr[1];
if(preg_match_all("/%\w{2}/",$str,$matches)){
for($i=0;$i<count($matches[0]);$i++){
$chr1=hexdec(substr($matches[0][$i],1));
$arr=array("f0","e0","c0","0");
for($j=0;$j<count($arr);$j++)if($chr1>hexdec($arr[$j]))break;
$chr=hexdec(substr($matches[0][$i],1))-hexdec($arr[$j]);
while(++$j<count($arr))$chr=$chr*0x40+(hexdec(substr($matches[0][++$i],1))-0x80);
$str=dechex($chr);
if(strlen($str)==4){
$p=hexdec(substr($str,0,2))-0x4d;
$q=hexdec(substr($str,2))*4;
$ret.=chr(hexdec(substr($this->qswhData[$p],$q,2)));
$ret.=chr(hexdec(substr($this->qswhData[$p],$q+2,2)));
}else
$ret.=chr(hexdec($str));
}
}
else{
if(strtolower($str[0])=="x")
$str=substr($str,1);
else
if(strlen($str)!=4)$str=dechex($str);
if(strlen($str)==4){
$p=hexdec(substr($str,0,2))-0x4d;
$q=hexdec(substr($str,2))*4;
$ret.=chr(hexdec(substr($this->qswhData[$p],$q,2)));
$ret.=chr(hexdec(substr($this->qswhData[$p],$q+2,2)));
}else
$ret.=chr(hexdec($str));
}
return $ret;
}
}
利用典范
$qswh=new qswhU("qswhU.php");//假如文件名是qswhU.php,可省参数
echo "<xmp>不带参数(默许过滤为:&#[num];):";
echo "\n".$qswh->decode("中文Abc");
echo "\n".$qswh->decode("中文Abc");
echo "\n挪用内置过滤(UTF转码):".$qswh->decode("%E4%B8%AD%E6%96%87%20!%22%23%24%25%26'()*%2B%2C%2F%3A%3B%3C%3D%3E%3F%40%5B%5D%5E%60%7B%7C%7D~%25Abc",1);
echo "\n挪用内置过滤unescape(%u[num]):".$qswh->decode("%u4E2D%u6587Abc",2);
echo "\n自界说过滤([x+num]):".$qswh->decode("[x4E2D][x6587][x41][x62][x63]","/\[(\w+)\]/");
后果以下:
不带参数(默许过滤为:&#[num];):
中文Abc
中文Abc
挪用内置过滤(UTF转码):中文 !"#$%&'()*+,/:;<=>?@[]^`{|}~%Abc
挪用内置过滤unescape(%u[num]):中文Abc
自界说过滤([x+num]):中文Abc
当然你可以把你最基本的功能放出来的时候就放出来,比如放到论坛上,让大家都参与, |
|