function.php
资源名称:BBWPS.rar [点击查看]
上传用户:yttaitong
上传日期:2009-05-10
资源大小:128k
文件大小:6k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
PHP
- <?
- /*
- [BBWPS!] (C)2006-2010 小蜜蜂版权所有.
- This is NOT a freeware, use is subject to license terms
- 时间:2007年12月
- 描述:函数
- */
- function Meta($time,$path){
- print("<meta http-equiv="refresh" content="$time;url=".$path."">");
- exit;
- }
- function MsgError($error){
- print("<script> alert('".$error."');window.history.go(-1);</script>");exit;
- }
- function ExeSuccess($msg,$path){
- print("<script> alert('".$msg."');</script>");
- print("<meta http-equiv="refresh" content="0;url=".$path."">");
- exit;
- }
- function show_split_page($currentPage,$allPage,$href,$sid=''){
- if($allPage<=1){
- return "<font color="#999999">首 页</font> <font color="#999999"><<上一页</font> <font color="#999999">下一页>></font> <font color="#999999">尾 页</font>";
- }
- if($currentPage==1&&$allPage>1&&$currentPage!=$allPage){
- $numberNext=$currentPage+1;
- return "<font color="#999999">首 页</font> <font color="#999999"><<上一页</font> <a href="".$href."&next=".$numberNext."&/msg-".$sid.".html"><span class="link2">下一页>></span></a> <a href="".$href."&next=".$allPage."&/msg-".$sid.".html"><span class="link2">尾 页</span></a>";
- }
- if($currentPage>1&&$allPage>1&&$currentPage!=$allPage){
- $numberNext=$currentPage+1; $numberPrvi=$currentPage-1;
- return "<a href="".$href."&next=1&/msg-".$sid.".html"><span class="link2">首 页</span></a> <a href="".$href."&next=".$numberPrvi."&/msg-".$sid.".html"><span class="link2"><<上一页</span></a> <a href="".$href."&next=".$numberNext."&/msg-".$sid.".html"><span class="link2">下一页>></span></a> <a href="".$href."&next=".$allPage."&/msg-".$sid.".html"><span class="link2">尾 页</span></a>";
- }
- if($allPage>1&&$currentPage==$allPage){
- $numberPrvi=$currentPage-1;
- return "<a href="".$href."&next=1&/msg-".$sid.".html"><span class="link2">首 页</span></a> <a href="".$href."&next=".$numberPrvi."&/msg-".$sid.".html"><span class="link2"><<上一页</span></a> <font color="#999999">下一页>></font> <font color="#999999">尾 页</font>";
- }
- return null;
- }
- function checkCacheOfSQL($sql){
- global $dirCacheSQL,$timeCacheSQL;
- $sqlMD5=md5($sql);
- if(file_exists($dirCacheSQL.$sqlMD5.".php")){
- $checkTime=filemtime($dirCacheSQL.$sqlMD5.".php");
- if((time()-$checkTime)<$timeCacheSQL*60){
- return $dirCacheSQL.$sqlMD5.".php";
- }
- else{
- produceCacheOfSQL($sql);
- return $dirCacheSQL.$sqlMD5.".php";
- }
- }
- else{
- produceCacheOfSQL($sql);
- return $dirCacheSQL.$sqlMD5.".php";
- }
- }
- function produceCacheOfSQL($sql){
- global $dirCacheSQL,$db;
- $result=$db->query($sql,true);
- $stringCacheSQL='<?PHP'."n";
- $i=0;
- while ($rs=$db->fetch_array($result)){
- foreach ($rs as $key=>$vlaue){
- $stringCacheSQL.='$resultOfArray['.$i.']["'.$key.'"]="'.addslashes($vlaue).'";'."n";
- }
- $i++;
- }
- $stringCacheSQL.="?>";
- $db->free();
- $sqlMD5=md5($sql);
- $fp=fopen($dirCacheSQL.$sqlMD5.".php","w");
- //flock($fp,1);
- fwrite($fp,$stringCacheSQL,strlen($stringCacheSQL));
- fclose($fp);
- touch($dirCacheSQL.$sqlMD5.".php",time());
- return true;
- }
- function getResultArray($sql){
- global $isCacheSQL,$db;
- if(!$isCacheSQL){
- $db->query($sql,true);
- while ($rs=$db->fetch_array()){
- $rsArray[]=$rs;
- }
- $db->free();
- unset($rs);
- return $rsArray;
- }
- else{
- $includePath=checkCacheOfSQL($sql);
- return $includePath;
- }
- }
- //----------------------------------
- //功能:获得SQL查询结果
- //参数:$sql //sql查询语句
- //返回:ARRAY
- //----------------------------------
- function getSQLResultArray($sql){
- $returnValue=getResultArray($sql);
- if(is_array($returnValue)){
- $rsArray=$returnValue;
- }
- else if($returnValue!=null){
- include_once($returnValue);
- $rsArray=$resultOfArray;
- }
- return $rsArray;
- }
- function getIP(){
- if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")){
- $ip = getenv("HTTP_CLIENT_IP");
- }elseif(getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")){
- $ip = getenv("HTTP_X_FORWARDED_FOR");
- }else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")){
- $ip = getenv("REMOTE_ADDR");
- }else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")){
- $ip = $_SERVER['REMOTE_ADDR'];
- }else{
- $ip = "unknown";
- }
- return($ip);
- }
- function get_title($str,$length){
- for($i=0;$i<$length;$i++){
- $string=ord(substr($str,$i,1));
- if($string>128){
- $chinese++;
- }
- }
- $l=strlen($str);
- if($l>=$length){
- if($chinese%2==0){
- return substr($str,0,$length);
- }
- else{
- $length++;
- return substr($str,0,$length);
- }
- }
- else{
- return substr($str,0,$l);
- }
- }
- function deltree($pathdir){
- if(!is_dir($pathdir))
- {
- rmdir($pathdir);
- }else{
- $d = dir($pathdir);
- while($a=$d->read()){
- $b = opendir($pathdir.'/'.$a);
- while (($file = readdir($b)) !== false) {
- if(($file=='.') || ($file=='..') || ($a=='.') || ($a=='..'))continue;
- unlink($pathdir.'/'.$a.$file);
- }
- if(is_dir($pathdir.'/'.$a) && ($a!='.') && ($a!='..'))
- {
- if(!is_dir($pathdir.'/'.$a)){
- deltree($pathdir.'/'.$a);
- }
- if(is_dir($pathdir.'/'.$a))
- {
- rmdir($pathdir.'/'.$a);
- return ture;
- }
- }
- }
- }
- $d->close();
- }
- function delHtml($string){
- $string = (trim(strip_tags($string,"<br>")));
- $bMsg=nl2br($string);
- $bMsg=str_replace("r","",$bMsg);
- $bMsg=str_replace("n","",$bMsg);
- $bMsg=str_replace("t","",$bMsg);
- $bMsg=preg_replace("/s+/","",$bMsg);
- if(preg_match("/<br />s*<br />/is",$bMsg)){
- preg_match_all("/<br />s+<br />/is",$bMsg, $matches);
- foreach($matches[0] as $value){
- $bMsg=str_replace($value,"",$bMsg);
- }
- $bMsg=preg_replace("/<brs+/>s*<brs+/>/is","<br />",$bMsg);
- $bMsg=preg_replace("/<brs*>s*<brs*>/is","<br />",$bMsg);
- }
- if(preg_match("/<br/><br/>/is",$bMsg)){
- preg_match_all("/<br/><br/>/is",$bMsg, $matches);
- foreach($matches[0] as $value){
- $bMsg=str_replace($value,"",$bMsg);
- }
- $bMsg=preg_replace("/<br/><br/>/is","",$bMsg);
- }
- $string = str_replace(" ","",$bMsg);
- $string = str_replace("<br/>","n",$bMsg);
- return $string;
- }
- ?>