php函数:一些使用频率比较高的PHP函数来源: 发布时间:星期二, 2008年12月30日 浏览:103次 评论:0
在php开发中
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 1.产生随机 ![]() ![]() function random($length) { $hash = @#@#; $chars = @#abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz@#; $max = strlen($chars) - 1; mt_srand((double)microtime ![]() for($i = 0; $i < $length; $i ![]() $hash .= $chars[mt_rand(0, $max)]; } ![]() } 2.截取 ![]() ![]() ![]() 注:该 ![]() function wordscut($ ![]() ![]() ![]() ![]() $length=$length - 3; $addstr=@# ...@#; } for($i = 0; $i < $length; $i ![]() ![]() ![]() $wordscut .= $ ![]() ![]() $i ![]() } ![]() $wordscut .= $ ![]() } } ![]() } ![]() ![]() } 3.取得客户端ip地址 function getip ![]() ![]() ![]() $ip = getenv("http_client_ip"); ![]() ![]() ![]() $ip = getenv("http_x_forwarded_for"); ![]() ![]() ![]() $ip = getenv("remote_addr"); ![]() ![]() ![]() ![]() $ip = $_server[@#remote_addr@#]; ![]() $ip = "unknown"; ![]() } 4.创建相应 ![]() function createdir($dir=@#@#) { ![]() { $temp = explode(@#/@#,$dir); $cur_dir = @#@#; for($i=0;$i<count($temp);$i ![]() { $cur_dir .= $temp[$i].@#/@#; ![]() { @mkdir($cur_dir,0777); } } } } 5.判断邮箱地址 function checkemail($inaddress) { ![]() } 6.跳转 function gotourl($message=@#@#,$url=@#@#,$title=@#@#) { $html ="<html><head>"; ![]() $html .="<metahttp-equiv=@#refresh@# content=\"3;url=@#".$url."@#\">"; $html .="<linkhref=@#../templates/style.css@# type=text/css rel=stylesheet>"; $html .="</head><body><br><br><br><br>"; $html .="<tablecellspacing=@#0@#cellpadding=@#0@#border=@#1@#width=@#450@#align=@#center@#>"; $html .="<tr><tdbgcolor=@##ffffff@#>"; $html .="<tableborder=@#1@#cellspacing=@#1@#cellpadding=@#4@#width=@#100%@#>"; $html .="<tr ![]() $html .="<td>".$title."</td></tr>"; $html .="<tr ![]() $html .="<br>".$message."<br><br>"; ![]() $html .="系统将在3秒后返回<br>如果您 ![]() ![]() $html .="[<a href=@##@#=@#history.go(-1)@#>返回</a>]"; $html .="</td></tr></table></td></tr></table>"; $html .="</body></html>"; echo $html; exit; } 7.分页(两个 ![]() function getpage($sql,$page_size=20) { global $page,$totalpage,$sums; //out param $page = $_get["page"]; //$eachpage = $page_size; $pagesql = strstr($sql," from "); $pagesql = "select count(*) as ids ".$pagesql; $result = mysql_query($pagesql); ![]() $totalpage = ceil($sums/$page_size); ![]() $startpos = ($page-1)*$page_size; $sql .=" limit $startpos,$page_size "; ![]() } function showbar($ ![]() { global $page,$totalpage; $out="共<font ".$totalpage."".$totalpage."color=@#red@#><b>".$totalpage."</b></font>页 "; $linknum =4; $start = ($page-round($linknum/2))>0 ? ($page-round($linknum/2)) : "1"; $end = ($page+round($linknum/2))<$totalpage ? ($page+round($linknum/2)) : $totalpage; $prestart=$start-1; $nextend=$end+1; ![]() $out .= "<ahref=@#?page=1&&".$ ![]() ![]() ![]() ![]() $out.="<ahref=@#?page=".$prestart."@# title=上 ![]() for($t=$start;$t<=$end;$t ![]() { $out .= ($page ![]() ![]() } ![]() $out.="<ahref=@#?page=".$nextend."&&".$ ![]() ![]() ![]() $out .= " <ahref=@#?page=".$totalpage."&&".$ ![]() ![]() } 8.获取新插入数据 ![]() <? mysql_insert_id ![]() ?> 本文来自: 脚本的家(www.jb51.net) 详细出处参考:http://www.jb51.net/article/16071.htm TAG: PHP ![]() 0
相关文章读者评论发表评论 |