| 常用函数,不用说的啦......... function message($C_alert,$I_goback='') { if(!empty($I_goback)) { echo "<script>alert('$C_alert');window.location.href='$I_goback';</script>"; } else { echo "<script>alert('$C_alert');</script>"; } } /** * 判断下拉菜音的选取项 * * 可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * * @access public * @param string $str1 要比较的字符串一 * @param string $str2 要比较的字符串二 * @return string 相等返回字符串"selected",否则返回空字符串 */ function selected($str1,$str2) { if($str1==$str2) { return ' selected'; } return ''; } /** * 截取中文部分字符串 * * 截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * * @access public * @param string $str 要处理的字符串 * @param int $strlen 要截取的长度默认为10 * @param string $other 是否要加上省略号,默认会加上 * @return string */ function showtitle($str,$strlen=10,$other=true) { $j = 0; for($i=0;$i<$strlen;$i++) if(ord(substr($str,$i,1))>0xa0) $j++; if($j%2!=0) $strlen++; $rstr=substr($str,0,$strlen); if (strlen($str)>$strlen && $other) return $rstr; }
///////////// function createdir($dir='') { if (!is_dir($dir)) { $temp = explode('/',$dir); $cur_dir = ''; for($i=0;$i<count($temp);$i++) { $cur_dir .= $temp[$i].'/'; if (!is_dir($cur_dir)) { @mkdir($cur_dir,0777); } } } } //////////// function dhtmlspecialchars($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = dhtmlspecialchars($val); } } else { $string = str_replace('&', '&', $string); $string = str_replace('"', '"', $string); $string = str_replace('<', '<', $string); $string = str_replace('>', '>', $string); $string = preg_replace('/&(#\d;)/', '&\1', $string); } return $string; } ///////// function daddslashes($string, $force = 0) { if(!$GLOBALS['magic_quotes_gpc'] || $force) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = daddslashes($val, $force); } } else { $string = addslashes($string); } } return $string; } /////////. function random($length) { $hash = ''; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $max = strlen($chars) - 1; mt_srand((double)microtime() * 1000000); for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } return $hash; } ////// function wordscut($string, $length ,$sss=0) { if(strlen($string) > $length) { if($sss){ $length=$length - 3; $addstr=' ...'; } for($i = 0; $i < $length; $i++) { if(ord($string[$i]) > 127) { $wordscut .= $string[$i].$string[$i + 1]; $i++; } else { $wordscut .= $string[$i]; } } return $wordscut.$addstr; } return $string; } ///////// function sizecount($filesize) { if($filesize >= 1073741824) { $filesize = round($filesize / 1073741824 * 100) / 100 . ' G'; } elseif($filesize >= 1048576) { $filesize = round($filesize / 1048576 * 100) / 100 . ' M'; } elseif($filesize >= 1024) { $filesize = round($filesize / 1024 * 100) / 100 . ' K'; } else { $filesize = $filesize . ' bytes'; } return $filesize; } //////////////// function gotourl($message='',$url='') { global $language; $html ="<html><head>"; if(!empty($url)) $html .="<meta http-equiv='refresh' content=\"1;url='".$url."'\">"; $html .="<link href='./html/style.css' type=text/css rel=stylesheet>"; $html .="</head><body><br><br><br><br>"; $html .="<table cellspacing='0' cellpadding='0' border='0' width='450' align='center'>"; $html .="<tr><td bgcolor='#000000'>"; $html .="<table border='0' cellspacing='1' cellpadding='4' width='100%'>"; $html .="<tr class='m_title'>"; $html .="<td>".$language['messagebox_title']."</td></tr>"; $html .="<tr class='line_1'><td align='center' height='60'>"; $html .="<br>".$message."<br><br>"; if (!empty($url)) $html .="[<a href=".$url." target=_self>".$language['messagebox_exp_1']."</a>]"; else $html .="[<a href='#' onclick='history.go(-1)'>".$language['messagebox_exp_2']."</a>]"; $html .="</td></tr></table></td></tr></table>"; $html .="</body></html>"; echo $html; exit; } ////////////// function sqldumptable($table, $startfrom = 0, $currsize = 0) { global $db, $multivol, $sizelimit, $startrow; $offset = 64; if(!$startfrom) { $tabledump = "DROP TABLE IF EXISTS $table;\n"; $createtable = $db->query("SHOW CREATE TABLE $table"); $create = $db->fetch_row($createtable); $tabledump .= $create[1].";\n\n"; } $tabledumped = 0; $numrows = $offset; while(($multivol && $currsize + strlen($tabledump) < $sizelimit * 1000 && $numrows == $offset) || (!$multivol && !$tabledumped)) { $tabledumped = 1; if($multivol) { $limitadd = "LIMIT $startfrom, $offset"; $startfrom += $offset; } $rows = $db->query("SELECT * FROM $table $limitadd"); $numfields = $db->num_fields($rows); $numrows = $db->num_rows($rows); while ($row = $db->fetch_row($rows)) { $comma = ""; $tabledump .= "INSERT INTO $table VALUES("; for($i = 0; $i < $numfields; $i++) { $tabledump .= $comma."'".mysql_escape_string($row[$i])."'"; $comma = ","; } $tabledump .= ");\n"; } } $startrow = $startfrom; $tabledump .= "\n"; return $tabledump; } ////////// function splitsql($sql){ $sql = str_replace("\r", "\n", $sql); $ret = array(); $num = 0; $queriesarray = explode(";\n", trim($sql)); unset($sql); foreach($queriesarray as $query) { $queries = explode("\n", trim($query)); foreach($queries as $query) { $ret[$num] .= $query[0] == "#" ? NULL : $query; } $num++; } return($ret); } |