方 法:先设置 $ob_function 为函数名列表(以“;”作间隔,需均为字符串处理函数,且便两个数可为一,可以使自定义变量),再设置 ob_start("ob_handle") 调用本函数进行缓存控制,最后 ob_end_flush() 输出缓存。(注: $ob_function 在 ob_end_flush() 之前设置均有效!)
*/
$ob_function = "htmlspecialchars;trim";
function ob_handle ($content) {
//Coded By Windy_sk 20030510 v1.0
global $ob_function, $cache_file;
$f_list = split(";", $ob_function);
for($i=0; $i<count($f_list); $i++) {
$temp = trim($f_list[$i]);
if(function_exists($temp)) $content = $temp($content);
}
if(phpversion() > "4.0.6") $content = ob_gzhandler($content, 1);
return $content;
}
/*
函数名:RndKey
作 用:生成规定长度的随机字串
方 法:RndKey(8) -> "1d@5cDO("
*/
function RndKey($lng){
$char_list = array();
$char_list[] = "1234567890";
$char_list[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$char_list[] = "abcdefghijklmnopqrstuvwxyz";
$char_list[] = "!@^()_:+\-";
$char_length = count($char_list);
$Rnd_Key = "";
for($i=1; $i<=$lng; $i++){
$Rnd_Str = $char_list[rand(1,$char_length) - 1];
$Rnd_Key .= substr($Rnd_Str, rand(0,strlen($Rnd_Str)-1), 1);
}
return($Rnd_Key);
}
/*
函数名:cut_words
作 用:将连续的文本按照全角字符和半角单词拆分
*/
function cut_words($str) {
//Coded By Windy_sk 20020805 v1.0
$str = str_replace("\r\n","\n",$str) . " ";
preg_match_all("/[\xa0-\xff]?./", $str, $arr1);
$arr1 = $arr1[0];
$arr2 = array();
$n = 0;
for($i=0; $i<count($arr1); $i++) {
if(ord($arr1[$i])>=0xa0) {
if(!empty($arr2[$n])) $n++;
$arr2[$n++] = $arr1[$i];
} elseif(preg_match("/\s/m", $arr1[$i])) {
$arr2[++$n] = $arr1[$i];
} else {
$arr2[$n] .= $arr1[$i];
}
}
return join("", $arr2);
}
?>