北京赛车有没有官网-2019河北中级经济师报名

首页

AD联系:507867812

北京赛车有没有官网

时间:2019-11-19 09:21:21 作者:注册免费送金的娱乐场 浏览量:85516

北京赛车有没有官网<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越phpfunction.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>,见下图

function.inc.php超越php

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>,见下图

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php,如下图

function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

如下图

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>,如下图

function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>,见图

北京赛车有没有官网function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

function.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

function.inc.php超越php

function.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>。

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

北京赛车有没有官网function.inc.php超越php

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>。

function.inc.php超越php

1.<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

function.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越phpfunction.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越phpfunction.inc.php超越php

2.function.inc.php超越php。

function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

3.<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>。

function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

4.<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>。

function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?><?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越phpfunction.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>function.inc.php超越phpfunction.inc.php超越php<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>。北京赛车有没有官网

展开全文
相关文章
拉斯维加斯博彩充值

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>

新太阳城娱乐加盟合作

function.inc.php超越php....

淘金盈国际娱乐线上

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>....

真人利来国际百家

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>....

亚洲涩徒

function.inc.php超越php....

相关资讯
竞彩足球app注册送

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>....

澳门不锈钢网304

<?php /** *GlobalFunction * *@authorAvenger<avenger@php.net> *@version1.14$Id2003-05-3010:10:08$ */ /** *弹出提示框 * *@accesspublic *@paramstring$txt弹出一个提示框,$txt为要弹出的内容 *@returnvoid */ functionpopbox($txt){ echo"<scriptlanguage='JavaScript'>alert('".$txt."')</script>"; } /** *非法操作警告 * *@accesspublic *@paramstring$C_alert提示的错误信息 *@paramstring$I_goback返回后返回到哪一页,不指定则不返回 *@returnvoid */ functionalert($C_alert,$I_goback='main.php'){ if(!empty($I_goback)){ echo"<script>alert('$C_alert');window.location.href='$I_goback';</script>"; }else{ echo"<script>alert('$C_alert');</script>"; } } /** *产生随机字符串 * *产生一个指定长度的随机字符串,并返回给用户 * *@accesspublic *@paramint$len产生字符串的位数 *@returnstring */ functionrandstr($len=6){ $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';//characterstobuildthepasswordfrom mt_srand((double)microtime()*1000000*getmypid());//seedtherandomnumbergenerater(mustbedone) $password=''; while(strlen($password)<$len) $password.=substr($chars,(mt_rand()%strlen($chars)),1); return$password; } /** *判断下拉菜音的选取项 * *可以判断字符串一和字符串二是否相等.从而使相等的项目在下拉菜单中被选择 * *@accesspublic *@paramstring$str1要比较的字符串一 *@paramstring$str2要比较的字符串二 *@returnstring相等返回字符串"selected",否则返回空字符串 */ functionckselect($str1,$str2){ if($str1==$str2){ return'selected'; } return''; } /** *一个自定义的Ftp函数 * *@accessprivate *@returnvoid */ functionmyftp($ftp_server,$ftp_port,$ftp_username,$ftp_password,$ftp_path='/'){ $ftpid=@ftp_connect($ftp_server,$ftp_port)ordie('ConnectToFtpServerError!'); @ftp_login($ftpid,$ftp_username,$ftp_password)ordie('LoginFtpError!'); @ftp_chdir($ftpid,'/'.$ftp_path)ordie('ChdirError!'); return$ftpid; } /** *截取中文部分字符串 * *截取指定字符串指定长度的函数,该函数可自动判定中英文,不会出现乱码 * *@accesspublic *@paramstring$str要处理的字符串 *@paramint$strlen要截取的长度默认为10 *@paramstring$other是否要加上省略号,默认会加上 *@returnstring */ functionshowtitle($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){$rstr.='...';} return$rstr; } /** *制作链接 * *@accesspublic *@paramstringurl要链接到的网址 *@paramstringlinktext显示的链接文字 *@paramstringtarget目标框架 *@paramstringextras扩展参数 *@returnstring */ functionmake_link($url,$linktext=false,$target=false,$extras=false){ returnsprintf("<ahref=\"%s\"%s%s>%s</a>", $url, ($target?'target="'.$target.'"':''), ($extras?''.$extras:''), ($linktext?$linktext:$url) ); } /** *格式化用户评论 * *@accesspublic *@paramstring *@returnvoid */ functionclean_note($text){ $text=htmlspecialchars(trim($text)); /*turnurlsintolinks*/ $text=preg_replace("/((mailto|http|ftp|nntp|news):.+?)(>|\s|\)|\"|\.\s|$)/","<ahref=\"\"></a>",$text); /*this'fixing'codewillgoawayeventually.*/ $fixes=array('<br>','<p>','</p>'); reset($fixes); while(list(,$f)=each($fixes)){ $text=str_replace(htmlspecialchars($f),$f,$text); $text=str_replace(htmlspecialchars(strtoupper($f)),$f,$text); } /*<p>tagsmakethingslookawfullyweird(breaksthingsoutofthe<code> tag).Justconvertthemto<br>'s */ $text=str_replace(array('<P>','<p>'),'<br>',$text); /*Remove</p>tagstopreventitfromshowingupinthenote*/ $text=str_replace(array('</P>','</p>'),'',$text); /*preservelinebreaks*/ $text=str_replace("\n","<br>",$text); /*thiswillonlybreaklonglines*/ if(function_exists("wordwrap")){ $text=wordwrap($text); } //Preservespacingofusernotes $text=str_replace("","",$text); return$text; } /** *获取图象信息的函数 * *一个全面获取图象信息的函数 * *@accesspublic *@paramstring$img图片路径 *@returnarray */ functiongetimageinfo($img){ $img_info=getimagesize($img); switch($img_info[2]){ case1: $imgtype="GIF"; break; case2: $imgtype="JPG"; break; case3: $imgtype="PNG"; break; } $img_size=ceil(filesize($img)/1000)."k"; $new_img_info=array( "width"=>$img_info[0], "height"=>$img_info[1], "type"=>$imgtype, "size"=>$img_size ); return$new_img_info; } /** *计算当前时间 * *以微秒为单位返回当前系统的时间 * *@accesspublic *@returnreal */ functiongetmicrotime(){ $tmp=explode('',microtime()); return(real)$tmp[1].substr($tmp[0],1); } /** *写文件操作 * *@accesspublic *@parambool *@returnvoid */ functionwfile($file,$content,$mode='w'){ $oldmask=umask(0); $fp=fopen($file,$mode); if(!$fp)returnfalse; fwrite($fp,$content); fclose($fp); umask($oldmask); returntrue; } /** *加载模板文件 * *@accesspublic *@returnvoid */ functiontpl_load($tplfile,$path='./templates/',$empty='remove'){ global$tpl; $path?'':$path='./templates/'; require_once'HTML/Template/PHPLIB.php'; $tpl=newTemplate_PHPLIB($path,$empty); $tpl->setFile('main',$tplfile); } /** *模板解析输出 * *@accesspublic *@returnvoid */ functiontpl_output(){ global$tpl; $tpl->parse('output','main'); $tpl->p('output'); } /** *邮件发送函数 * *@accesspublicprivate *@parambool *@returnvoid */ functionmailSender($from,$to,$title,$content){ $from?$from='sender@phpe.net':''; $title?$title='FromExceedPHP...':''; $sig=" 感谢您使用我们的服务.\n\n ExceedPHP(超越PHP)\n $maildate\n\n --------------------------------------------------------------------------------------- \n\n 去发现极限方法的唯一办法就是去超越它\n 超越PHP欢迎您(http://www.phpe.net)\n "; $content.=$sig; if(@mail($to,$title,$content,"From:$from\nReply-To:$from")){ returntrue; }else{ returnfalse; } } functionbr2none($str){ returnstr_replace(array('<br>','<br/>'),"",$str); } /** *UBB解析 * *@paramnone *@accesspublic *@returnvoid */ functionubbParse($txt,$coverhtml=0){ if($coverhtml==0)$txt=nl2br(new_htmlspecialchars($txt));//BR和HTML转换 //只转换BR,不转换HTML if($coverhtml==1){ if(!preg_match('/<\s*(p|br)\s*>/is',$txt)&&!preg_match('/<table.+<\/table>/is',$txt)){ $txt=strip_tags($txt); $txt=nl2br($txt); }else{ $txt=str_replace('<?','<?',$txt); } } //preandquote //error_reporting(E_ALL); $txt=preg_replace("#\[quote\](.+?)\[/quote\]#is","<blockquote></blockquote>",$txt); $txt=preg_replace("#\[code\](.+?)\[/code\]#ise","'<preclass=php>'.br2none('').'</pre>'",$txt); //Colors支持篏套 while(preg_match("#\[color=([^\]]+)\](.+?)\[/color\]#is",$txt)){ $txt=preg_replace("#\[color=([^\]]+)\](.+?)\[/color\]#is","<spanstyle='color:'></span>",$txt); } //Align $txt=preg_replace("#\[center\](.+?)\[/center\]#is","<center></center>",$txt); $txt=preg_replace("#\[left\](.+?)\[/left\]#is","<divalign=left></div>",$txt); $txt=preg_replace("#\[right\](.+?)\[/right\]#is","<divalign=right></div>",$txt); //Sub&sup $txt=preg_replace("#\[sup\](.+?)\[/sup\]#is","<sup></sup>",$txt); $txt=preg_replace("#\[sub\](.+?)\[/sub\]#is","<sub></sub>",$txt); //emailtags //[email]avenger@php.net[/email][email=avenger@php.net]Emailme[/email] $txt=preg_replace("#\[email\](\S+?)\[/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*\"\;([\.\w\-]+\@[\.\w\-]+\.[\.\w\-]+)\s*\"\;\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); $txt=preg_replace("#\[email\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/email\]#i","<ahref='mailto:'></a>",$txt); //urltags //[url]http://www.phpe.net[/url][url=http://www.phpe.net]ExceedPHP![/url] $txt=preg_replace("#\[url\](\S+?)\[/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); $txt=preg_replace("#\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]#i","<ahref=''target='_blank'></a>",$txt); //Startoffwiththeeasystuff $txt=preg_replace("#\[b\](.+?)\[/b\]#is","<b></b>",$txt); $txt=preg_replace("#\[i\](.+?)\[/i\]#is","<i></i>",$txt); $txt=preg_replace("#\[u\](.+?)\[/u\]#is","<u></u>",$txt); $txt=preg_replace("#\[s\](.+?)\[/s\]#is","<s></s>",$txt); //Headertext $txt=preg_replace("#\[h([1-6])\](.+?)\[/h[1-6]\]#is","<h></h>",$txt); //Images $txt=preg_replace("#\[img\](.+?)\[/img\]#i","<ahref=''target='_blank'><imgalt='Clicktofullsize'src=''border='0'onload='javascript:if(this.width>500)this.width=500'align='center'hspace='10'vspace='10'></a><br/>",$txt); //Attach $txt=preg_replace("#\[attach\s*=\s*\"\;\s*(\S+?)\s*\"\;\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); $txt=preg_replace("#\[attach\s*=\s*(\S+?)\s*\](.*?)\[\/attach\]#i","<ahref=''target='_blank'><b>相关附件:</b></a>",$txt); //Iframe $txt=preg_replace("#\[iframe\](.+?)\[/iframe\]#i","<divalign='center'><iframesrc=''style='width:96%;height:400px'></iframe><brclear='all'><ahref=''target='_blank'>在新窗口打开链接</a></div>",$txt); //(c)(r)and(tm) $txt=preg_replace("#\(c\)#i","©",$txt); $txt=preg_replace("#\(tm\)#i","™",$txt); $txt=preg_replace("#\(r\)#i","®",$txt); return$txt; } //重新格式化日期 functionformat_date($date){ if(!preg_match('/^\d+$/',$date))$date=strtotime(trim($date)); $sec=time()-$date; //Sec1dayis86400 if($sec<86400){ returnround($sec/3600).'hoursago'; }elseif($sec<(86400*7)){ returnround($sec/86400).'daysago'; }elseif($sec<(86400*7*4)){ returnround($sec/(86400*7)).'weeksago'; }else{ returndate('Y-m-d',$date); } } ?>....

热门资讯