=224) { //如果ASCII位高与224, $returnstr=$returnstr.substr($sourcestr,$i,3); //根据UTF-8编码规范,将3个连续的字符计为单个字符 $i=$i+3; //实际Byte计为3 $n++; //字串长度计1 } elseif ($ascnum>=192){ //如果ASCII位高与192, $returnstr=$returnstr.substr($sourcestr,$i,2); //根据UTF-8编码规范,将2个连续的字符计为单个字符 $i=$i+2; //实际Byte计为2 $n++; //字串长度计1 } elseif ($ascnum>=65 && $ascnum<=90){ //如果是大写字母, $returnstr=$returnstr.substr($sourcestr,$i,1); $i=$i+1; //实际的Byte数仍计1个 $n++; //但考虑整体美观,大写字母计成一个高位字符 } else { //其他情况下,包括小写字母和半角标点符号, $returnstr=$returnstr.substr($sourcestr,$i,1); $i=$i+1; //实际的Byte数计1个 $n=$n+0.5; //小写字母和半角标点等与半个高位字符宽... } if ($n <= $startlength){ $returnstr = ''; continue; } } if ($str_length>$cutlength){ $returnstr = $returnstr . "..."; //超过长度时在尾处加上省略号 } return $returnstr; } function Paging($page,$nur,$url) { echo"首 页"; if($page>=2){echo"上一页";} $nur_i=$page%10; if($nur_i==0){echo "[".$page."]";} $nur_i=$page/10; $num_i = intval($nur_i); for($i=(10*$num_i+1);$i<=(10*$num_i+10)&&$i<=$nur;$i++) { if($page==$i){$str='class="cover"';}else{$str='';} echo "[".$i."]"; } if($page<$nur){echo"下一页";} echo"尾 页"; } function ShowMessages($href,$messages=NULL) { if(!empty($messages)){echo"";} if(!empty($href)){echo"";exit(0);} } function GetSqlArray($array = array()) { $newarray = array(); foreach($array as $i=>$key) { $newarray[$i] = check_sql($key); } return $newarray; } function AddSql($data,$tb,$datano = array()) { foreach($data as $i=>$key) { if(!in_array($i,$datano)){ $need .= $i.","; $show .= "'".$key."',"; } } $need = substr($need, 0, -1); $show = substr($show, 0, -1); $sql = "insert into ".$tb."(".$need.")values(".$show.")"; if(mysql_query($sql)) { return array("MessageID"=>"1"); } else { return array("MessageID"=>"0","error"=>$sql); } } function ChangeSql($data,$where,$tb,$datano = array()) { foreach($data as $i=>$key) { if(!in_array($i,$datano)){ $update .= $i."='".$key."',"; } } foreach($where as $i=>$key) { $wheres .= "(".$i."='".$key."') and "; } $update = substr($update, 0, -1); $wheres = substr($wheres, 0, -5); $sql = "update ".$tb." set ".$update." where ".$wheres; if(mysql_query($sql)) { return array("MessageID"=>"1"); } else { return array("MessageID"=>"0","error"=>$sql); } } function SelectSql($tb,$where=NULL,$limit=NULL) { $rs = mysql_query("select * from ".$tb.$where.$limit); $i = 0; while($rst = mysql_fetch_array($rs)) { $rsts[$i] = $rst; $i++; } return $rsts; } function FindSql($tb,$where=NULL,$limit=NULL) { $rs = mysql_query("select * from ".$tb.$where.$limit); $rst = mysql_fetch_array($rs); return $rst; } function PagingSql($tb,$where=NULL,$page=1,$num,$url) { $rse=mysql_query("select * from ".$tb.$where); $nu=mysql_num_rows($rse); $nur=ceil($nu/$num); $sql="select * from ".$tb.$where." limit ".(($page-1)*$num).",".$num; $pages = ""; $pages = "首页"; if($page>=2){$pages .= "<上一页";} $nur_i=$page%10; if($nur_i==0){$pages .= "".$page."";} $nur_i=$page/10; $num_i = intval($nur_i); for($i=(10*$num_i+1);$i<=(10*$num_i+10)&&$i<=$nur;$i++) { if($page==$i){ $pages .= "".$i.""; }else{ $pages .= "".$i.""; } } if($page<$nur){$pages .= "下一页>";} $pages .= "尾页"; return array("sql"=>$sql,"page"=>$pages); } function check_sql($str) { $str = htmlspecialchars($str); return $str; } function operationLog($title,$userid,$type,$db,$sp=NULL) { $data[title] = $title; $data[userid] = $userid; $data[type] = $type; $data[db] = $db; if(!empty($sp)){ $data[sp] = $sp; } $data['time'] = date("Y-m-d H-i-s"); $data[ip] = getenv(REMOTE_ADDR); AddSql($data,'tb_log'); } ?>