gusucode.com > 数码公司网站源码程序 > 数码公司网站源码程序/guestbook/includes/guestbook.inc.php

    <?php


GuestBookConfig();


//模块参数设置
function GuestBookConfig(){

	global $msql;

	$msql->query("select * from {P}_guestbook_config");
	while($msql->next_record()){
	
	$variable=$msql->f('variable');
	$value=$msql->f('value');
	$GLOBALS["PHOTOCONF"][$variable]=$value;
	}

}


//统计字符串长度-UTF8
function utf8_strlen($str, $th) {  //$th表示是否替换特殊符号
	if($th==1){
		$str=str_replace('&amp;', '&', $str);
		$str=str_replace('\&quot;', '"', $str);
		$str=str_replace('&lt;', '<', $str);
		$str=str_replace('&gt;', '>', $str);
		$str=str_replace("\'", "'", $str);
		$str=str_replace("\\\\", "\\", $str);
	}
	$count = 0;
	for($i = 0; $i<strlen($str); $i++){
		$value = ord($str[$i]);
		if($value>127) {
			$count++;
			if($value>= 192 && $value <= 223) $i++;
			elseif($value>= 224 && $value <= 239) $i = $i + 2;
			elseif($value>= 240 && $value <= 247) $i = $i + 3;
			//else die(‘Not a UTF-8 compatible string‘);
		}elseif($value<128){
			$count++;
		}
	}
	return $count;
}


//中文,英文,数字混合字符串截取-UTF8
function hsubstr($str,$length) {
	for($i = 0; $i < $length; $i++){
		$value = ord($str[$i]);
		if($value > 127) {
			if($value >= 192 && $value <= 223){
				if($i<=$length){
					$length+=1;
				}
				$i++;
			}elseif($value >= 224 && $value <= 239){
				if($i<=$length){
					$length+=2;
				}
				$i += 2;
			}elseif($value >= 240 && $value <= 247){
				if($i <= $length){
					$length+=3;
				}
				$i += 3;
			}
		}
	}

	$hstr=substr($str,0,$length);
	return $hstr;
}

?>