您的位置:首页 > 产品设计 > UI/UE

自己用的函数

2004-11-11 14:39 417 查看
<?php
//----------------------------------------------
function query1($sql)
{
 $query  =  mysql_query($sql) or die(mysql_error());
 return $query;
}
//------------- 取得符合条件的行数 -------------
function rownum($sql)
{
 $res  =  query1($sql);
 $num  =  mysql_num_rows($res);
 return $num;
}
//------------ 将取得的值以一个阵列的形式返回 -----
function s_array($sql)
{
 $array  =  array(); 
 $res    =  query1($sql);
 $i      =  0; 
 while($arr =  mysql_fetch_array($res))
 {
  $array[$i] = $arr;
  $i++;
 }
 return $array;
}

//------------------------  全局用的函数 ------------------------------------------
function query($vars,$table,$condition)
{
 $sql="select $vars from $table $condition";
 $result=mysql_query($sql) or die(mysql_error());
 return $result;
}
//-------------------------- END ------------------------------------------------
/*********************************  字段处理  ************************************/
function TextFilter($str)
 {
        $str = chop($str); 
  $str = quotemeta($str);
     $str = nl2br( htmlspecialchars( $str) );
  $str = addslashes($str);
     return $str;
     }
//------------------------取出数据时的处理情况----------------------------------------
function opentext($str)
{
 $str=StripSlashes($str);
 $str=StripSlashes($str);
 $str=nl2br($str);
    return $str;
}
/****************************    showShort()处理字段的函数  **********************************/
Function csubstr($str,$start,$len)
{
    $strlen=strlen($str);
    $clen=0;
    for($i=0;$i<$strlen;$i++,$clen++)
    {
       if ($clen>=$start+$len)
       break;
       if(ord(substr($str,$i,1))>0xa0)
         {
           if ($clen>=$start)
           $tmpstr.=substr($str,$i,2);
           $i++;
         }
       else
        {
         if ($clen>=$start)
         $tmpstr.=substr($str,$i,1);
        }
    }
  return $tmpstr;
}
Function showShort($str,$len)
   {
     $tempstr = csubstr($str,0,$len);
  //---------- 在此调用上面的函数 --------------
     if ($str<>$tempstr)
     $tempstr .= "..."; //要以什么结尾,修改这里就可以.
     return $tempstr;
   }
//-----------------------     分页函数     ------------------------------------
function listpage($list_page,$page,$query,$table,$condition)
{
 //---------------------   $pages        总页数 ------------------------
 //---------------------   $start        起始页 ------------------------
 //---------------------   $page         当前页 ------------------------
 //---------------------   $pre          前一页 ------------------------
 //---------------------   $next         下一页 ------------------------
 //---------------------   $list_page    每页要显示的条数  --------------
 //---------------------   $table        所要查询的表 ------------------
 //---------------------   $condition    查询的条件 --------------------
 $result=mysql_query($query) or die(mysql_error());
 $num=@mysql_num_rows($result);
 if($num<$page_list)
 { $pages="1";}
 else
 { $pages=@ceil($num/$list_page);}
 if(!isset($stard))
 { $stard="0"; }
 if(!isset($page)){ $page=1;}
 $start=($page-1)*$list_page;
 $pre=$page-1;
 $next=$page+1;
 $sql="select * from $table  $condition limit $start,$list_page";
 $result1=mysql_query($sql);
 $numm=@mysql_num_rows($result1);
 $array=array();
    $array[0] = $page."|".$pages."|".$pre."|".$next;
 $i =1 ;
 while($arr=@mysql_fetch_array($result1))
 {
  $array[$i]=$arr;
  $i++;
 }
 return $array;
}
//------------------------  分页显示为 |<< < ..[1].2.3.4.5.6 ..> >>|  -----------------
function number_show($array,$condition)
{
 //------------------  $page   第几页 -------------------------------
 //------------------  $page   总页数 -------------------------------
 //------------------  $page   跳转的条件 ---------------------------
 //---  说明:此程序还要提高一节来实现显示如:|<<...<< n-2,n-1,n,n+1,n+2>>...>>| (其中的n为自动添加的)
 $arr=explode("|",$array);
    $page=$arr[0];
 $pages=$arr[1];
 $pre=$arr[2];
 $next=$arr[3];
 echo "总页数($pages): ";
 if($page>0&&$page<=$pages)
 {
  if($page>3)
  {
      echo "<a href=$PHP_SELF?page=1&$condition title=首页><< 第一页 </a>...";
  }
  if($page>1)
  {
   echo "<a href=$PHP_SELF?page=$pre&$condition title=上一页> <<</a>";
  }
  $page1=$page-2;
  $page2=$page-1;
  $page3=$page+1;
  $page4=$page+2;
  if($page1>0)
  {
  echo " <a href=$PHP_SELF?page=$page1&$condition>$page1</a>";
  }
  if($page2>0)
  {
  echo " <a href=$PHP_SELF?page=$page2&$condition>$page2</a>";
  }
  echo " [$page]";
  if($pages>=$page3)
  //if($page3!=$pages)
  {
  echo " <a href=$PHP_SELF?page=$page3&$condition>$page3</a>"; 
  }
  //if((($pages+1)>$page4)&&($pages!=$page))
  if($pages>=$page4)
  {
  echo " <a href=$PHP_SELF?page=$page4&$condition>$page4</a>";
  }
  if(($pages-$page-2)>0)
  {
   echo " <a href=$PHP_SELF?page=$next&$condition title=下一页>>></a>";
  }
  if(($pages-$page-3)>0)
  {
   echo " ...<a href=$PHP_SELF?page=$pages&$condition title=尾页>最后一页>></a>";
  }
 }
}
function online()
{
 //-------------  $update_time 用户在线的更新的时间-------------------------
 session_start();
 $SID=session_id();
 $ip = getenv('REMOTE_ADDR');
 if($SESSION["name"]!="")
 {  
      $result=mysql_query("select count(userid) from $table4 where userid='$SESSION[name]'");
   $num=@mysql_result($result,"0");
   if($num!=0)
  {
           $result=mysql_query("update $table4 set time='$time' where userid='$SESSION[name]'",$dbh);
           bbs_log($table4,$PHP_SELF,"update");
     if(!$result){ echo mysql_error();}
       }
   else
     {
   $result=@mysql_query("insert into $table4 (SID,userid,ip,time) values ('$SID','$SESSION[name]','$ip','$time')",$dbh);
   bbs_log($table4,$PHP_SELF,"insert");
   if(!$result){ echo mysql_error();}
     }
 }
 else
 {
   $userid="guest";
   //$SESSION["name"]="guest";
      $result=mysql_query("select count(ip) from $table4 where ip='$ip'");
   $num=@mysql_result($result,"0");
   if($num!=0)
  {
    $result=mysql_query("update $table4 set time='$time' where ip='$ip'");
    bbs_log($table4,$PHP_SELF,"update");
  }
   else
  {
    $result=@mysql_query("insert into $table4 (SID,userid,ip,time) values ('$SID','guest','$ip','$time')",$dbh);
    bbs_log($table4,$PHP_SELF,"insert");
    if(!$result){ echo "guest";/*echo mysql_error();*/}
     }
 }
 $del_time=$time-$update_times;
 $upde=@mysql_query("delete from $table4 where time<'$del_time'",$dbh);
 bbs_log($table4,$PHP_SELF,"delete");
}

//---------------------------------    UBB代码处理     -------------------------------------------
/*
粗体
 文本   文本
斜体
 文本   文本
下划线
 文本   文本
字体大小
 [size=3]文本[/size]   文本
字体颜色
 [color=red]文本[/color]  文本
[color=#887766]文本[/color]  文本
嵌套运用
 [size=3][color=#889900]这是字体例子[/color][/size]
输入网址
 网站名称 如:山顶洞人
输入邮箱
[email]simple[/email]  如:<a href=mailto:simple>simple</a>
还可以使用表情
simple

simple

[sig]simple[/sig]
自动判断网址
 网址后面必须是空格、回车、中文或者无任何字符
PHP语法加亮
 [php]
echo "hello world";
[/php]
echo "hello word";
*/
//---------------------------------   END UBB   ----------------------------------------
// ####################### 清除HTML代码 #######################
function html_clean($content){
 $content = htmlspecialchars($content);
 $content = str_replace("/n", "<br>", $content);
 $content = str_replace("  ", "  ", $content);
 $content = str_replace("/t", '    ', $content);
 return $content;
}
function ubb($Text) {
  $Text=htmlspecialchars($Text);
  $Text=ereg_replace("/r/n","<br>",$Text);
  $Text=ereg_replace("/r","<br>",$Text);
  $Text=nl2br($Text);
  $Text=preg_replace("///t/is","  ",$Text);
  $Text=preg_replace("//[h1/](.+?)/[//h1/]/is","<h1>//1</h1>",$Text);
  $Text=preg_replace("//[h2/](.+?)/[//h2/]/is","<h2>//1</h2>",$Text);
  $Text=preg_replace("//[h3/](.+?)/[//h3/]/is","<h3>//1</h3>",$Text);
  $Text=preg_replace("//[h4/](.+?)/[//h4/]/is","<h4>//1</h4>",$Text);
  $Text=preg_replace("//[h5/](.+?)/[//h5/]/is","<h5>//1</h5>",$Text);
  $Text=preg_replace("//[h6/](.+?)/[//h6/]/is","<h6>//1</h6>",$Text);
  $Text=preg_replace("//[url/](http:////.+?)/[//url/]/is","<a href=//1>//1</a>",$Text);
  $Text=preg_replace("//[url/](.+?)/[//url/]/is","<a href=/"http:////1/">http:////1</a>",$Text);
  $Text=preg_replace("//(.*)/[//url/]/is","<a href=//1>//2</a>",$Text);
  $Text=preg_replace("//[url=(.+?)/](.*)/[//url/]/is","<a href=http:////1>//2</a>",$Text);
  $Text=preg_replace("//[img/](.+?)/[//img/]/is","<img src=//1><br>/n",$Text);
  $Text=preg_replace("//[color=(.+?)/](.+?)/[//color/]/is","<font color=//1>//2</font>",$Text);
  $Text=preg_replace("//[size=(.+?)/](.+?)/[//size/]/is","<font size=//1>//2</font>",$Text);
  $Text=preg_replace("//[sup/](.+?)/[//sup/]/is","<sup>//1</sup>",$Text);
  $Text=preg_replace("//[sub/](.+?)/[//sub/]/is","<sub>//1</sub>",$Text);
  $Text=preg_replace("//[pre/](.+?)/[//pre/]/is","<pre>//1</pre>",$Text);
  $Text=preg_replace("//[email/](.+?)/[//email/]/is","<a href=mailto://1>//1</a>",$Text);
  $Text=preg_replace("//[i/](.+?)/[//i/]/is","<i>//1</i>",$Text);
  $Text=preg_replace("//[b/](.+?)/[//b/]/is","<b>//1</b>",$Text);
  $Text=preg_replace("//[u/](.+?)/[//u/]/is","<u>//1</u>",$Text);
  //------------ 表情按钮的替换-------------------------------
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///1.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///2.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///3.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///4.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///5.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///6.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///7.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///8.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///9.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///10.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///11.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///12.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///13.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///14.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///15.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///16.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///17.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///18.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///19.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///20.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///21.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///22.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///23.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///24.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///25.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///26.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///27.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///28.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///29.gif border=0 hspace=0 vspace=0>",$Text);
  $Text=preg_replace("//[:([0-9]{1,2})/]/U","<img src=images/icons///30.gif border=0 hspace=0 vspace=0>",$Text);  //------------- PHP 代码处理 ----------------
  $Text=preg_replace("//[php/](.+?)/[//php/]/is","&<? //1 ?>",$Text);
  //------------------- 引用处理程序
  $Text=preg_replace("//[quote/](.+?)/[//quote/]/is","<TABLE bgColor=#eeffff border=1 borderColorDark=white  borderColorLight=#777777 cellSpacing=0 height=80 width=600><TBODY><TR><TD vAlign=top><FONT color=#999999><P>//1</P></FONT></TD></TR></TBODY></TABLE>", $Text);
  //------------------- flash 处理程序  -----------
  $Text=preg_replace("//[flash/](.+?)/[//flash/]/is","<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0 width=500 height=400><param name=movie value=//1><param name=quality value=high><embed src=//1 quality=high pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash width=500 height=400></embed></object>", $Text);
  //------------------ real 播放器处理程序 ---------
  $Text=preg_replace("//[real/](.+?)/[//real/]/is","<object classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA            height=285 id=RAOCX name=rmplay width=356><param name=SRC value=//1><param name=CONSOLE value=Clip1>  <param name=CONTROLS value=imagewindow><param name=AUTOSTART value=true><embed  src=//1  autostart=true             controls=ImageWindow console=Clip1 pluginspage=http://www.real.com width=356 height=285></embed></object><object classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA height=27 id=video1 width=356><param name=_ExtentX value=7276>    <param name=_ExtentY value=1058><param name=AUTOSTART value=0><param name=SHUFFLE value=0><param name=PREFETCH value=0><param name=NOLABELS value=0><param name=CONTROLS value=ControlPanel><param name=CONSOLE value=Clip1><param name=LOOP value=0><param name=NUMLOOP value=0><param name=CENTER value=0><param name=MAINTAINASPECT value=0><param name=BACKGROUNDCOLOR value=#ffffff><embed type=audio/x-pn-realaudio-plugin console=Clip1controls=ControlPanel height=27 width=356 autostart=0 _extentx=7276 _extenty=1058 shuffle=0 prefetch=0 nolabels=0 loop=0 numloop=0 center=0 maintainaspect=0 backgroundcolor=#ffffff></embed></object>", $Text);
  //------------------ Media 播放器处理程序 --------
  $Text=preg_replace("//[media/](.+?)/[//media/]/is","<object align=middle class=OBJECT classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 height=320 id=MediaPlayer width=356><param name=ShowStatusBar value=-1><param name=Filename value=//1 <embed type=application/x-oleobject  codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=//1 width=356 height=320></embed></object>", $Text);
  $Text=preg_replace("//[code/](.+?)/[//code/]/is","<blockquote><font size='1' face='Times New Roman'>code:</font><hr color='lightblue'><i>//1</i><hr color='lightblue'></blockquote>", $Text);  
   $Text=preg_replace("//[sig/](.+?)/[//sig/]/is","<div style='text-align: left; color: darkgreen; margin-left: 5%'><br><br>--------------------------<br>//1<br>--------------------------</div>", $Text);
return $Text;
}
//----------------------- 用于修改资料的时候对UBB代码进行反解 -------------------
function unubb($Text)
{
  $Text=str_replace(" "," ",$Text);
  $Text=str_replace("<br>","/n",$Text);
  $Text=str_replace("<br>/n","/n",$Text);
  //----------------- 引用部分字段处理的反编  -------------------------
  $Text = eregi_replace(quotemeta("<TABLE bgColor=#eeffff border=1 borderColorDark=white  borderColorLight=#777777 cellSpacing=0 height=80 width=600><TBODY><TR><TD vAlign=top><FONT color=#999999><P>"),"
",$Text);
  $Text = eregi_replace(quotemeta("</P></FONT></TD></TR></TBODY></TABLE>"),"
",$Text);
 // $Text=preg_replace("//<TABLE bgColor=#eeffff border=1 borderColorDark=white  borderColorLight=#777777 cellSpacing=0 height=80 width=600/>/<TBODY/>/</TR/>/<TD vAlign=top/>/<FONT color=#999999/>/<P/>(.+?)/<//P/>/<//FONT/>/<//TD>/<//TR/>/<//TBODY/>/<//TABLE/>/is","
//1
", $Text);
  //----------------- 对常见的字体,颜色等属性进行反编 -----------------
  $Text=preg_replace("//<h1/>(.+?)/<//h1/>/is","[h1]//1[/h1]",$Text);
  $Text=preg_replace("//<h2/>(.+?)/<//h2/>/is","[h1]//1[/h1]",$Text);
  $Text=preg_replace("//<h3/>(.+?)/<//h3/>/is","[h1]//1[/h1]",$Text);
  $Text=preg_replace("//<h4/>(.+?)/<//h4/>/is","[h1]//1[/h1]",$Text);
  $Text=preg_replace("//<h5/>(.+?)/<//h5/>/is","[h1]//1[/h1]",$Text);
  $Text=preg_replace("//<h6/>(.+?)/<//h6/>/is","[h1]//1[/h1]",$Text);
  $Text=preg_replace("//<h7/>(.+?)/<//h7/>/is","[h1]//1[/h1]",$Text);
  $Text=preg_replace("//<font color=(.+?)/>(.+?)/<//font/>/is","[color=//1]//2[/color]",$Text);
  $Text=preg_replace("//<font size=(.+?)/>(.+?)/<//font/>/is","[size=//1]//2[/size]",$Text);
  $Text=preg_replace("//<sup/>(.+?)/<//sup/>/is","[sup]//1[/sup]",$Text);
  $Text=preg_replace("//<sub/>(.+?)/<//sub/>/is","[sub]//1[/sub]",$Text);
  $Text=preg_replace("//<pre/>(.+?)/<//pre/>/is","[pre]//1[/pre]",$Text);
  $Text=preg_replace("//<i/>(.+?)/<//i/>/is","//1",$Text);
  $Text=preg_replace("//<b/>(.+?)/<//b/>/is","//1",$Text);
  $Text=preg_replace("//<u/>(.+?)/<//u/>/is","//1",$Text);
  //-------------------  反编表情代码 ----------------------------
  $Text=preg_replace("//<img src=images//icons//1.gif border=0 hspace=0 vspace=0/>/is","[:1]",$Text);
  $Text=preg_replace("//<img src=images//icons//2.gif border=0 hspace=0 vspace=0/>/is","[:2]",$Text);
  $Text=preg_replace("//<img src=images//icons//3.gif border=0 hspace=0 vspace=0/>/is","[:3]",$Text);
  $Text=preg_replace("//<img src=images//icons//4.gif border=0 hspace=0 vspace=0/>/is","[:4]",$Text);
  $Text=preg_replace("//<img src=images//icons//5.gif border=0 hspace=0 vspace=0/>/is","[:5]",$Text);
  $Text=preg_replace("//<img src=images//icons//6.gif border=0 hspace=0 vspace=0/>/is","[:6]",$Text);
  $Text=preg_replace("//<img src=images//icons//7.gif border=0 hspace=0 vspace=0/>/is","[:7]",$Text);
  $Text=preg_replace("//<img src=images//icons//8.gif border=0 hspace=0 vspace=0/>/is","[:8]",$Text);
  $Text=preg_replace("//<img src=images//icons//9.gif border=0 hspace=0 vspace=0/>/is","[:9]",$Text);
  $Text=preg_replace("//<img src=images//icons//10.gif border=0 hspace=0 vspace=0/>/is","[:10]",$Text);
  $Text=preg_replace("//<img src=images//icons//11.gif border=0 hspace=0 vspace=0/>/is","[:11]",$Text);
  $Text=preg_replace("//<img src=images//icons//12.gif border=0 hspace=0 vspace=0/>/is","[:12]",$Text);
  $Text=preg_replace("//<img src=images//icons//13.gif border=0 hspace=0 vspace=0/>/is","[:13]",$Text);
  $Text=preg_replace("//<img src=images//icons//14.gif border=0 hspace=0 vspace=0/>/is","[:14]",$Text);
  $Text=preg_replace("//<img src=images//icons//15.gif border=0 hspace=0 vspace=0/>/is","[:15]",$Text);
  $Text=preg_replace("//<img src=images//icons//16.gif border=0 hspace=0 vspace=0/>/is","[:16]",$Text);
  $Text=preg_replace("//<img src=images//icons//17.gif border=0 hspace=0 vspace=0/>/is","[:17]",$Text);
  $Text=preg_replace("//<img src=images//icons//18.gif border=0 hspace=0 vspace=0/>/is","[:18]",$Text);
  $Text=preg_replace("//<img src=images//icons//19.gif border=0 hspace=0 vspace=0/>/is","[:19]",$Text);
  $Text=preg_replace("//<img src=images//icons//20.gif border=0 hspace=0 vspace=0/>/is","[:20]",$Text);
  $Text=preg_replace("//<img src=images//icons//21.gif border=0 hspace=0 vspace=0/>/is","[:21]",$Text);
  $Text=preg_replace("//<img src=images//icons//22.gif border=0 hspace=0 vspace=0/>/is","[:22]",$Text);
  $Text=preg_replace("//<img src=images//icons//23.gif border=0 hspace=0 vspace=0/>/is","[:23]",$Text);
  $Text=preg_replace("//<img src=images//icons//24.gif border=0 hspace=0 vspace=0/>/is","[:24]",$Text);
  $Text=preg_replace("//<img src=images//icons//25.gif border=0 hspace=0 vspace=0/>/is","[:25]",$Text);
  $Text=preg_replace("//<img src=images//icons//26.gif border=0 hspace=0 vspace=0/>/is","[:26]",$Text);
  $Text=preg_replace("//<img src=images//icons//27.gif border=0 hspace=0 vspace=0/>/is","[:27]",$Text);
  $Text=preg_replace("//<img src=images//icons//28.gif border=0 hspace=0 vspace=0/>/is","[:28]",$Text);
  $Text=preg_replace("//<img src=images//icons//29.gif border=0 hspace=0 vspace=0/>/is","[:29]",$Text);
  $Text=preg_replace("//<img src=images//icons//30.gif border=0 hspace=0 vspace=0/>/is","[:30]",$Text);  //-----------------  END --------------------------------------
  //--------------- 反处理 FLASH 程序----------------------------
  $Text=preg_replace("//<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http:////download.macromedia.com//pub//shockwave//cabs//flash//swflash.cab#version=6,0,29,0 width=500 height=400/>/<param name=movie value=(.+?)/>/<param name=quality value=high/>/<embed src=(.+?) quality=high pluginspage=http:////www.macromedia.com//go//getflashplayer type=application//x-shockwave-flash width=500 height=400/>/<//embed/>/<//object/>/is","[flash]//1[/flash]",$Text);
  //--------------  反处理 real 程序----------------------------
  $Text=preg_replace("//<object classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA            height=285 id=RAOCX name=rmplay width=356/>/<param name=SRC value=(.+?)/>/<param name=CONSOLE value=Clip1/>  /<param name=CONTROLS value=imagewindow/>/<param name=AUTOSTART value=true/>/<embed  src=(.+?)  autostart=true             controls=ImageWindow console=Clip1 pluginspage=http:////www.real.com width=356 height=285/>/<//embed/>/<//object/>/<object classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA height=27 id=video1 width=356/>/<param name=_ExtentX value=7276/>    /<param name=_ExtentY value=1058/>/<param name=AUTOSTART value=0/>/<param name=SHUFFLE value=0/>/<param name=PREFETCH value=0/>/<param name=NOLABELS value=0/>/<param name=CONTROLS value=ControlPanel/>/<param name=CONSOLE value=Clip1/>/<param name=LOOP value=0/>/<param name=NUMLOOP value=0/>/<param name=CENTER value=0/>/<param name=MAINTAINASPECT value=0/>/<param name=BACKGROUNDCOLOR value=#ffffff/>/<embed type=audio//x-pn-realaudio-plugin console=Clip1controls=ControlPanel height=27 width=356 autostart=0 _extentx=7276 _extenty=1058 shuffle=0 prefetch=0 nolabels=0 loop=0 numloop=0 center=0 maintainaspect=0 backgroundcolor=#ffffff/>/<//embed/>/<//object/>/is","[real]//1[/real]",$Text);
  //----------------反处理 Media 程序 ---------------------------
  $Text=preg_replace("//<object align=middle class=OBJECT classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 height=320 id=MediaPlayer width=356/>/<param name=ShowStatusBar value=-1/>/<param name=Filename value=(.+?) /<embed type=application//x-oleobject  codebase=http:////activex.microsoft.com//activex//controls//mplayer//en//nsmp2inf.cab#Version=5,1,52,701 flename=mp src=(.+?) width=356 height=320/>/<//embed/>/<//object/>/is","[media]//1[/media]",$Text);
  //-------------  END ------------------------------------------------------------------------------------
  $Text=preg_replace("//<font size=(.+?)/>(.+?)/<//font/>/is","[size=//1]//2[/size]",$Text);
  $Text=preg_replace("//<font color=(.+?)/>(.+?)/<//font/>/is","[color=//1]//2[/color]",$Text);
  $Text=preg_replace("//<a href=mailto:(.+?)/>(.+?)/<//a/>/is","[email]//1[/email]",$Text);
  $Text=preg_replace("//<img src=(.+?)/>/is","",$Text);
  $Text=preg_replace("//<a href=(.+?)/>(.+?)/<//a/>/is","[url=//1]//2
",$Text);
  return $Text;
}
//-------------------  为解决<br>问题写的函数  -----------------------
function managebr($string)
{
 $string=str_replace(""," ",$string);
    $string=str_replace("/n","<br>",$string);
    $string=str_replace("/n","<br>/n",$string);
 $string=preg_replace("/<br>/is","<br>",$string);
 $string=preg_replace("//</? (.+?)/?/>/is","<?//1?>",$string);
 return $string;
}
//------------   论坛标题长度的限制    --------------------------------------------------------
function subject($bbs_title)
{
  if(strlen($bbs_title)>60)
   {
     for($i=0;$i<58;$i++)//避免截取乱码
     if(ord(substr($bbs_title,$i,1))>128)
        $i++;
     $bbs_title=substr($bbs_title,0,$i);
   }
   return $bbs_title;
}

//-------------  限制图片不超过的最大值
function image_w_h($src,$w,$h)
{
 $data=getImageSize($src);
 $width=$data[0];//为图片宽度
 $height=$data[1];//为图片高度
 if($width>$w)
  $image_w=$w;
 if($width<$w)
  $image_w=$width;
 if($height>$h)
  $image_h=$h;
 if($height<$h)
  $image_h=$height;
 $array=array("width"=>$image_w,"height"=>$image_h);
 return $array;
}

/*$array=image_w_h("http://cimg.163.com/lady/0404/13/1081746550.jpg","400","500");
echo $array['width'];
echo "<br>/n".$array['height'];
echo "<br>/n";
echo "<img src=http://cimg.163.com/lady/0404/13/1081746550.jpg width='".$array['width']."' height='".$array['height']."'>";
*/
/*日期合法性检查函数

关键词:PHP

这个函数可以用来检查年月日形式的日期合法性,您只要稍作修改便可以检查其它形式的日期合法性.功能:
日期合法性检查
返回:
true(合法)|false(不合法)
参数:
$ymd 年月日形式的日期
$sep 年月日之间的分隔符,缺省为-
*/
function datecheck($ymd,$sep='-'){
$parts = explode($sep,$ymd);
$year = $parts[0];
$month = $parts[1];
$day = $parts[2];

if(isint($year) && isint($month) && isint($day)){
if(checkdate($month,$day,$year)) return true;
else return false;
}
else return false;
}

function isint($str){
$str = (string)$str;

$pos = 0;
$len = strlen($str);
for($i=0;$i<$len;$i++){
if($str[$i]=='0') $pos++;
else break;
}
$str = substr($str,$pos);

$int = (int)$str;
if($str==(string)$int) return true;
else return false;
}
//--- 取出两个时间相差的秒数
function get_day($s_time,$e_time)//$time是unix时间戳,得到秒数
{
if (!$s_time&&!$e_time) return false;
$s_time = strtotime($s_time);
$e_time = strtotime($e_time);
$s_diff =$e_time - $s_time;
$dis_day=$s_diff/(3600*24);
return $dis_day;
}

//---- 取得用户的IP
function iptype1 () {
if (getenv("HTTP_CLIENT_IP")) {
   return getenv("HTTP_CLIENT_IP");
}
else {
   return "none";
}
}
function iptype2 () {
if (getenv("HTTP_X_FORWARDED_FOR")) {
   return getenv("HTTP_X_FORWARDED_FOR");
}
else {
   return "none";
}
}
function iptype3 () {
if (getenv("REMOTE_ADDR")) {
   return getenv("REMOTE_ADDR");
}
else {
   return "none";
}
}
function ip() {
$ip1 = iptype1();
  $ip2 = iptype2();
$ip3 = iptype3();
if (isset($ip1) && $ip1 != "none" && $ip1 != "unknown") {
   return $ip1;
}
elseif (isset($ip2) && $ip2 != "none" && $ip2 != "unknown") {
   return $ip2;
}
elseif (isset($ip3) && $ip3 != "none" && $ip3 != "unknown") {
   return $ip3;
}  
  else {
  return "none";
}
}

//警告函数
//取得程序执行的时间微秒
function getmicrotime()
{
   list($usec, $sec) = explode(" ",microtime());
   return ((double)$usec + (double)$sec);
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息