1.產生隨機字串函數
function random($length) {
$hash = ''; uvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i
for($i = 0; = $chars[mt_rand(0, $max)];
}
return $hash;
}
?>
}
?>
註:此函數對GB2312使用有效
function wordscut($string, $length ,$sss=0) wordscut($string, $length ,$s=0) ($string) > $length) {
if($sss){ th - 3;
$addstr=' ...); ( $i = 0; $i if(ord($string[$i]) > 127) { $i ;
} else {
$wordscut . return $wordscut.$addstr;
}
return $string;
}
?>
function GetIP(){
if (getenv("HTTP_CLIENT_IP") strcasecmp(getenv("HTTP_CLIENT_IP") $ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") &&&&&&&&&&&&&&&&&&什麼(getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR' ] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
else
$ip $ip);
}
?>
4.建立對應的資料夾
function createdir($dir='''') 🎜> if (!is_dir($dir))
{
$cur_dir = '';
for($i=0; $i {
if (!is_dir($cur_dir))
@mkdir($cur_dir,0777);
}
}
}
?>
5.電話位址
5.
function checkEmail($inAddress)
{
return (ereg("^([a-zA-Z0-9_-]) @([9 -zA-Z0-9_-]) (.[a-zA-Z0-9_-]) ",$inAddress));
}
?>
6.跳轉
function gotourl($message='',$url='',$title='')
{
"";
if(!empty($url))
$html .="";
$html .="";
type=text/css rel=stylesheet>";
head>
";
$html .="";
$html .=""; $html .=""; $html .=""; $html .="".$title." td> |
"; $html .=""; $html .=" ".$message."
"; if (!empty($url)) $html .="系統將在3秒後返回 如果您的瀏覽器不能自動返回,請點選[這裡]進入"; else $ ='history.go(-1)'>回傳]"; $html .=" |
|
";
$html .="";
echo $html;
exit;
}
? >
7.分頁(兩個函數搭配使用)
function getpage($,$page_size=20)
function getpage($,$page_size=20) {
全域$page,$totalpage,$sums; //輸出參數
$page = 🎜> $pagesql = strstr($sql,"來自");
$pagesql = 「選擇count(*) 作為ids」.$pagesql;
mysql_fetch_array($result)) $sums = $rs[0];
$totalpage = ceil($sums/$page_size); page=1;
$startpos = ($page-1)*$page_size;
$sql .=" limit $startpos
函數showbar($string="")
{
全域 $page,$totalpage;
$out=" $page color='red'>頁 ";
$linkNum =4;
$start = ($page-round($linkNum/2))>0 $start = ($page-round($linkNum/2))>0 $start = ($page-round($linkNum/2))>0 ($link? 2)) : 「1」;
$end = ($page round($linkNum/2)) $nextend=$end 1;
if($page1)
$out .= "第一頁一>「;
if($start>1)
$out.="..「;
for($t=$start;$t {
$out {
($page==$t) ? "[".$t."] " : "$t ";
}
if($end $out.=">>..";
if($page$totalpage)
$out .= ;最後一頁";
返回$out;
}
? >
http://www.bkjia.com/PHPjc/317337.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/317337.htmlTechArticle1.產生隨機字串函數?php functionrandom($length){ $hash=''; $chars= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $max=strlen($chars)-1; mt_srand((雙...