返回列表 回复 发帖

[转帖]冰冰通用函数整理主题(updata 12/29/2003)

  1. function enCode($string) {
  2. $string=trim($string);
  3. $string=htmlspecialchars($string);
  4. $string = addslashes($string);
  5. $string=str_replace("'","’",$string);
  6. $string=str_replace("r","",$string);
  7. $string=str_replace("n","
  8. n",$string);
  9. return $string;
  10. }
复制代码
from iZz Website by Binzy @ iZz Studio
  1. <?php
  2. //----------------------------------------------------------------------------------------------------//
  3. // showpage();                                                                                                        //
  4. // Binzy [URL=http://www.JustDN.org]http://www.JustDN.org[/URL]                                                                              //
  5. //----------------------------------------------------------------------------------------------------//
  6. function showpage($total_num,$list_num,$file_name) {
  7. global $PAGE;
  8. //---------------- GET THE TOTAL PAGE NUMBER -------------------//
  9. $page_num=ceil($total_num/$list_num);
  10. //--------------------------------------------------------------------------//
  11. $StartPage = $PAGE - 5;
  12. if ( $StartPage < 1 ) $StartPage = 1;
  13. $LastPage = $StartPage + 9;
  14. if ( $LastPage > $page_num ) $LastPage = $page_num;
  15. if ( $LastPage != $StartPage +9 ) $StartPage = $LastPage - 9;
  16. if ( $StartPage < 1 ) $StartPage = 1;
  17. if ( $PAGE ==1 ) {$PrePage = "<";} else { $PrePage = "[URL=$file_name&PAGE=]<[/URL]";}
  18. if ( $PAGE == $page_num ) {$NextPage = ">";} else { $NextPage = "[URL=$file_name&PAGE=]>[/URL]";}
  19. //----------------------------------- A Foolish Mothed  But I Think It is Good~~ ---------------------------------------//
  20. ?>
  21. <table border="0" cellspacing="1" cellpadding="2" bgcolor="#CCCCCC">
  22. <tr bgcolor="#F0F0F0">
  23.    <td width="15" align="center" height="15"><?=$PrePage?></td>
  24. <?
  25. while ( $StartPage <= $LastPage ) {
  26. if ( $StartPage == $PAGE ) {
  27.   $ShowPage = "<font color="">".$StartPage."</font>";
  28.   $bgcolor = "bgcolor="#E0E0E0"";
  29. }else{
  30.   $ShowPage = "[URL=$file_name&PAGE=]".$StartPage."[/URL]";
  31.   $bgcolor = "";
  32. }
  33. ?>
  34.    <td width="15" align="center" height="15" <?=$bgcolor?>>[b]<?=$ShowPage?>[/b]</td>
  35. <?
  36. $StartPage++;
  37. }
  38. ?>
  39.    <td width="15" align="center" height="15"><?=$NextPage?></td>
  40.    <td align="center" height="15">[b]Total:[/b]<?=$total_num?></td>
  41. </tr>
  42. </table>
  43. <?php
  44. }
  45. ?>
复制代码
from iZz Website by Binzy @ iZz Studio
  1. //Using like Array_Insert($InsData,$Tables);
  2. /*
  3. Define the array,format like:
  4. $InsData[name]="name";
  5. $InsData[url]="http://www.justdn.org";
  6. $InsData[email]="xsharp@justdn.com";
  7. //the db table will insert into
  8. $Tables = "$table_name";
  9. */
  10. function Array_Insert($InsData,$Table){
  11. global $db;
  12. $InsData_Num = Count($InsData);
  13. $Foreach_I = 0;
  14. $query = "Insert into ".$Table." (";
  15. $query_key = "";
  16. $query_val = "";
  17. foreach($InsData as $key=>$val){
  18. $Foreach_I = $Foreach_I + 1;
  19. if(!empty($val)){ //为空则不插入,否则出错
  20. if($Foreach_I < $InsData_Num){
  21. $query_key .= $key.",";
  22. $query_val .= "'".$val."',";
  23. }else{
  24. $query_key .= $key; //最后一个没有","
  25. $query_val .= "'".$val."'";
  26. }}
  27. }
  28. $query .=$query_key.") Values (".$query_val.")";
  29. if($result = $db->query($query)){
  30. echo "
  31. --------------------------------------------------------------------------------
  32. $query
  33. --------------------------------------------------------------------------------
  34. 数据更新成功!!
  35. "; //显示SQL语句,真正使用时不需要
  36. Return true;
  37. }else{
  38. $db->error($result);
  39. echo "数据更新失败!请参考下面错误信息:
  40. --------------------------------------------------------------------------------
  41. ";
  42. echo mysql_error();
  43. echo "
  44. --------------------------------------------------------------------------------
  45. ";
  46. echo "
  47. --------------------------------------------------------------------------------
  48. SQL语句是:$query
  49. --------------------------------------------------------------------------------
  50. ";
  51. Return false;
  52. }
  53. }
复制代码
  1. //-----------------使用方法----同上----------------------------------------------------
  2. function Array_Update($InsData,$Table,$Where){
  3. global $db;
  4. $InsData_Num = Count($InsData);
  5. $Foreach_I = 0;
  6. $query = "update ".$Table." set ";
  7. $query_key = "";
  8. $query_val = "";
  9. foreach($InsData as $key=>$val){
  10. $Foreach_I = $Foreach_I + 1;
  11. if(!empty($val)){ //为空则不插入,否则出错
  12. if($Foreach_I < $InsData_Num){
  13. $query_key = $key." = ";
  14. $query_val = "'".$val."',";
  15. $query .= $query_key.$query_val;
  16. }else{
  17. $query_key = $key." = "; //最后一个没有","
  18. $query_val = "'".$val."' ";
  19. $query .= $query_key.$query_val;
  20. }
  21. }
  22. }
  23. $query .= " $Where";
  24. if($result = $db->query($query)){
  25. echo "
  26. --------------------------------------------------------------------------------
  27. $query
  28. --------------------------------------------------------------------------------
  29. 数据更新成功!!
  30. "; //显示SQL语句,真正使用时不需要
  31. Return true;
  32. }else{
  33. $db->error($result);
  34. echo "数据更新失败!请参考下面错误信息:
  35. --------------------------------------------------------------------------------
  36. ";
  37. echo mysql_error();
  38. echo "
  39. --------------------------------------------------------------------------------
  40. ";
  41. echo "
  42. --------------------------------------------------------------------------------
  43. SQL语句是:$query
  44. --------------------------------------------------------------------------------
  45. ";
  46. Return false;
  47. }
  48. }
复制代码
  1. //--------------------------------------------------------------------------------------------------//
  2. // Function: GetIP
  3. // -----------------------
  4. // Parameters:
  5. // None
  6. //
  7. // Return:
  8. // Browser's IP
  9. //
  10. // What It's For:
  11. // Get IP
  12. //
  13. //--------------------------------------------------------------------------------------------------//
  14. function GetIP() {
  15. $IP=getenv('REMOTE_ADDR');
  16. $IP_ = getenv('HTTP_X_FORWARDED_FOR');
  17. if (($IP_ != "") && ($IP_ != "unknown")) $IP=$IP_;
  18. return $IP;
  19. }
复制代码
  1. function ReadFromFile($file_name,$f_start=0,$f_end=0)
  2. { if ($f_end==0) $f_end=filesize($file_name);
  3. $fp=@fopen($file_name,"r");
  4. fseek($fp,$f_start);
  5. flock($fp,1);
  6. $file_data=fread($fp,$f_end);
  7. fclose($fp);
  8. return $file_data;
  9. }
  10. function WriteToFile($filename,$data,$method="a")
  11. { $fp=@fopen($filename,$method);
  12. flock($fp,2);
  13. fwrite($fp,$data);
  14. fclose($fp);
  15. }
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。

[转帖]冰冰通用函数整理主题(updata 12/29/2003)

  1. /****************************************************************************
  2. db_mssql_class.php - description
  3. -------------------
  4. begin : 2002 4 2
  5. $Id: db_mssql_class.php,v 1.1 2002/04/03 09:25:33 Simon.Qiu Exp $
  6. /****************************************************************************/
  7. class DB_Handle{
  8. var $ClassName = "DB_Handle";
  9. var $Server;
  10. var $UserName;
  11. var $Password;
  12. var $Database;
  13. var $LinkID=0;
  14. var $QueryResult="";
  15. var $LastInsertID = "";
  16. /* private ignore=>ignore the error and continue, halt=>report the error and halt, report=>report the error and continue */
  17. var $Halt_On_Error = "report";
  18. var $Error = "";
  19. var $ErrNo = 0;
  20. /**public
  21. * remark: This is the db_mysql_class's structure
  22. * function: Set the server,username,password,database variable.
  23. */
  24. function DB_Handle($server="",$username="",$password="",$database=""){
  25. $this->Server = $server;
  26. $this->UserName = $username;
  27. $this->Password = $password;
  28. $this->Database = $database;
  29. }
  30. /**public
  31. * function: Connect database and select database
  32. * success: retun 1
  33. * failed: return 0
  34. */
  35. function connect(){
  36. $this->LinkID = @mssql_pconnect($this->Server,$this->UserName,$this->Password);
  37. if(!$this->LinkID){
  38. $this->halt("mssql_pconnect($this->Server,$this->UserName,$this->Password): Failed");
  39. return 0;
  40. }
  41. if(!@mssql_select_db($this->Database)){
  42. $this->halt("mssql_select_db($this->Database) Failed.");
  43. return 0;
  44. }
  45. return 1;
  46. }
  47. /**public
  48. * function: Check the database, if exist then select
  49. * exist: return 1
  50. * not exist: return 0
  51. */
  52. function selectDatabase(){
  53. if(@mssql_select_db($this->Database))
  54. return 1;
  55. else
  56. return 0;
  57. }
  58. /**public
  59. * function: Execute SQL instruction
  60. * success: return SQL Result.
  61. * failed: return 0;
  62. */
  63. function execQuery($sql=""){
  64. if($this->LinkID == 0){
  65. $this->halt("Execute SQL Failed: Hava not valid database connect.");
  66. return 0;
  67. }
  68. ob_start();
  69. $this->QueryResult = mssql_query($sql,$this->LinkID);
  70. $error = ob_get_contents();
  71. ob_end_clean();
  72. if($error){
  73. $this->halt("Execute SQL: mssql_query($sql,$this->LinkID) failed.");
  74. return 0;
  75. }
  76. $reg = "#insert into#";
  77. if(preg_match($reg,$sql)){
  78. $sql = "select @@IDENTITY as id";
  79. $res = mssql_query($sql,$this->LinkID);
  80. $this->LastInsertID = mssql_result($res,0,id);
  81. }
  82. return $this->QueryResult;
  83. }
  84. /**public
  85. * function: Get the query result's row number
  86. * success: return the row fo the Result
  87. * failed: return 0
  88. */
  89. function getTotalRowNum($result=""){
  90. if($result != "") $this->QueryResult = $result;
  91. $row = @mssql_num_rows($this->QueryResult);
  92. if($row >= 0) return $row;
  93. $this->halt("Get a row of result Failed: Result $result is invalid.");
  94. return 0;
  95. }
  96. /**public
  97. * function: Get the last insert record's id
  98. * success: return id
  99. * failed: return 0
  100. */
  101. function lastInsertID(){
  102. return $this->LastInsertID;
  103. }
  104. /**public
  105. * function: Get a field's value
  106. * success: return value of the field
  107. * failed: return 0
  108. */
  109. function getField($result="",$row=0,$field=0){
  110. if($result != "") $this->QueryResult = $result;
  111. $fieldvalue = @mssql_result($this->QueryResult,$row,$field);
  112. if($fieldvalue != "") return $fieldvalue;
  113. $this->halt("Get field: mssql_result($this->QueryResult,$row,$field) failed.");
  114. return 0;
  115. //Here should have error handle
  116. }
  117. /**public
  118. * function: Get next record
  119. * success: return a array of the record's value
  120. * failed: return 0
  121. */
  122. function nextRecord($result=""){
  123. if($result != "") $this->QueryResult = $result;
  124. $record = @mssql_fetch_array($this->QueryResult);
  125. if(is_array($record)) return $record;
  126. //$this->halt("Get the next record Failed: the Result $result is invalid.");
  127. return 0;
  128. }
  129. /**public
  130. * function: Free the Query Result
  131. * success return 1
  132. * failed: return 0
  133. */
  134. function freeResult($result=""){
  135. if($result != "") $this->QueryResult = $result;
  136. return @mssql_free_result($this->QueryResult);
  137. }
  138. /**public
  139. * function: Set the Halt_On_Error's state
  140. * success: return 1
  141. * failed: return 0
  142. */
  143. function setHaltOnError($state="ignore"){
  144. if(!($state == "ignore" || $state == "report" || $state == "halt")){
  145. $this->halt("Set the Halt_On_Error Fail: There is no state value $state");
  146. return 0;
  147. }
  148. $this->Halt_On_Error = $state;
  149. return 1;
  150. }
  151. /**public
  152. * function: Get the Halt_On_Error's state
  153. */
  154. function getHaltOnError(){
  155. return $this->Halt_On_Error;
  156. }
  157. /**public
  158. * function: Get the class's name
  159. */
  160. function toString(){
  161. return $this->ClassName;
  162. }
  163. /**private
  164. * function: Error handle
  165. */
  166. function halt($msg){
  167. $this->Error = @mysql_error($this->LinkID);
  168. $this->ErrNo = @mysql_errno($this->LinkID);
  169. if ($this->Halt_On_Error == "ignore") return;
  170. $this->makeMsg($msg);
  171. if ($this->Halt_On_Error == "halt") die("Session halted");
  172. }
  173. /**private
  174. * function: Make error information and print
  175. */
  176. function makeMsg($msg){
  177. printf("Database error: %s
  178. n", $msg);
  179. printf("MySQL Error: %s (%s)
  180. n",$this->ErrNo,$this->Error);
  181. }
  182. }
  183. ?>
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。

[转帖]冰冰通用函数整理主题(updata 12/29/2003)

  1. programming run time
  2. /*
  3. sky_travel@963.net
  4. http://www.wps2000.net
  5. */
  6. class timer {
  7. var $StartTime = 0;
  8. var $StopTime = 0;
  9. var $TimeSpent = 0;
  10. function start(){
  11. $this->StartTime = microtime();
  12. }
  13. function stop(){
  14. $this->StopTime = microtime();
  15. }
  16. function spent() {
  17. if ($this->TimeSpent) {
  18. return $this->TimeSpent;
  19. }
  20. else {
  21. $StartMicro = substr($this->StartTime,0,10);
  22. $StartSecond = substr($this->StartTime,11,10);
  23. $StopMicro = substr($this->StopTime,0,10);
  24. $StopSecond = substr($this->StopTime,11,10);
  25. $start = doubleval($StartMicro) + $StartSecond;
  26. $stop = doubleval($StopMicro) + $StopSecond;
  27. $this->TimeSpent = $stop - $start;
  28. return substr($this->TimeSpent,0,8);
  29. }
  30. } // end function spent();
  31. } //end class timer;
  32. // examples:
  33. $timer = new timer;
  34. $timer->start();
  35. $db=mysql_connect("localhost","root","");
  36. mysql_select_db("test");
  37. $temp=10000;
  38. $table='comment';
  39. for($i=0;$i<$temp;$i++){
  40. mysql_query ("insert into $table (username,commentTitle,commentText) values('just test!','i'm china girl','i konwn u and you know me!so i very happy because of you smile')");
  41. //insert SQL
  42. }
  43. $timer->stop();
  44. echo "insert into the $table total $temp record,run time ".$timer->spent()."second ,average record spent".$timer->spent/$temp."second";
  45. ?>
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。

[转帖]冰冰通用函数整理主题(updata 12/29/2003)

izz data object

by icer,xsharp@izz
  1. <?
  2. Class iDataO
  3. {
  4. var $insData; //array to store data from form or database
  5. var $checkpass; //if pass the data check
  6. var $errinfo; //array to store error message
  7. //-------------------------------------------------
  8. //   构造函数
  9. //-------------------------------------------------
  10. function iDataO(){
  11. $this->checkpass = true;
  12. }
  13. //-------------------------------------------------
  14. //   获取数组信息
  15. //-------------------------------------------------
  16. function getForm($tmpArray){
  17. foreach($tmpArray as $key=>$val)
  18. {
  19. $this->insData[$key] = $val;
  20. //  echo "$key -- $val n
  21. ";
  22. }
  23. //exit;
  24. }
  25. //-------------------------------------------------
  26. //   return the InsData
  27. //-------------------------------------------------
  28. Function getData(){
  29. return $this->insData;
  30. }
  31. //-------------------------------------------------
  32. //   数组中添加数据
  33. //-------------------------------------------------
  34. Function addData($key,$val){
  35. $this->insData[$key] = $val;
  36. }
  37. //-------------------------------------------------
  38. //   数组中删除数据
  39. //-------------------------------------------------
  40. Function delData($key){
  41. unset($this->insData[$key]);
  42. }
  43. //-------------------------------------------------
  44. //   数组中改变数据
  45. //-------------------------------------------------
  46. Function chgData($key,$val){
  47. $this->insData[$key] = $val;
  48. }
  49. //-------------------------------------------------
  50. //   数组信息插入数据库
  51. //-------------------------------------------------
  52. Function dataInsert($Table) //insert article data to database
  53. {
  54. If(!$this->checkpass){
  55. return 0; //error,data check not pass
  56. }Else{
  57. global $db;
  58. //-------------------------------------------------
  59. //   构建SQL语句
  60. //-------------------------------------------------
  61. // $insData_Num = Count($this->insData);
  62. $Foreach_I = 0;
  63. $query = "Insert into ".$Table." n(n";
  64. $query_key = "";
  65. $query_val = "";
  66. foreach($this->insData as $key=>$val){
  67.   if(strlen($val)>0){
  68.    if($Foreach_I == 0){
  69.     $query_key .= $key;
  70.     $query_val .= "'".$this->ensql($val)."'";
  71.    }else{
  72.     $query_key .= ",n".$key;
  73.     $query_val .= ",n'".$this->ensql($val)."'";
  74.    }
  75.    $Foreach_I = $Foreach_I + 1;
  76.   }
  77. }
  78. $query .=$query_key."n) nValues n(n".$query_val."n)";
  79. //-------------------------------------------------
  80. //   SQL语句执行
  81. //   echo $query;
  82. //   exit;
  83. //-------------------------------------------------
  84. if($result = $db->query($query)){
  85. Return true;
  86. }else{
  87. $result=$db->error();
  88. $this->errinfo[] = "数据库错误:数据插入失败。MySQL_ERRNO:".$result[code].".  MySQL_ERROR:".$result[message];
  89. $db->report = phphighlite("$query"); //SQL语句赋值给$db->report
  90. Return false;
  91. }
  92. }
  93. }
  94. Function dataUpdata($table,$where)
  95. {
  96. If (!$this->checkpass)
  97. {
  98.   return 0; //error,data check not pass
  99. }
  100. Else
  101. {
  102. //-------------------------------------------------
  103. //   构建SQL语句
  104. //-------------------------------------------------
  105.    global $db;
  106.       $Foreach_I = 0;  
  107.       $query = "update ".$table." set ";
  108.       $query_key = "";
  109.       $query_val = "";
  110.     foreach($this->insData as $key=>$val)
  111. {
  112.                if(strlen($val)>0)  //为空则不插入,否则出错
  113.      {
  114.         if($Foreach_I == 0)
  115.        {
  116.                         $query_key = $key;
  117.                         $query_val = "='".$this->ensql($val)."'";
  118.         $query .= $query_key.$query_val;
  119.                    }
  120.       else
  121.        {
  122.                         $query_key = ",".$key;
  123.                         $query_val = "='".$this->ensql($val)."'";
  124.         $query .= $query_key.$query_val;
  125.                    }
  126.                 $Foreach_I = $Foreach_I + 1;
  127.      }
  128.        }
  129.   $query .= " $where";
  130. //-------------------------------------------------
  131. //   SQL语句执行
  132. //   echo $query;
  133. //   exit;
  134. //-------------------------------------------------
  135.       if($db->query($query))
  136.    {
  137.            Return true;
  138.          }
  139.    else
  140.     {
  141.        $result=$db->error();
  142.     $this->errinfo[] = "<P>数据库错误:数据更新失败。MySQL_ERRNO:".$result[code].".  MySQL_ERROR:".$result[message]."</P>";
  143.     $db->report = phphighlite("$query");
  144.         Return false;
  145.       }
  146. }
  147. }
  148. //)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
  149. Function dataDel($table,$which,$id,$method="=")
  150. {
  151. If (!$this->checkpass)
  152. {
  153.   return 0; //error,data check not pass
  154. }
  155. Else
  156. {
  157. //-------------------------------------------------
  158. //   构建SQL语句
  159. //-------------------------------------------------
  160.    global $db;
  161.       $query = "Delete From ".$table." where ".$which.$method.$id;
  162.       if($db->query($query))
  163.    {
  164.            Return true;
  165.          }
  166.    else
  167.     {
  168.        $result=$db->error();
  169.     $this->errinfo[] = "<P>数据库错误:数据更新失败。MySQL_ERRNO:".$result[code].".  MySQL_ERROR:".$result[message]."</P>";
  170.     $db->report = phphighlite("$query");
  171.         Return false;
  172.       }
  173. }
  174. }
  175. //(((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
  176. function ensql($string) {
  177. $string=trim($string);
  178. $string=str_replace("'","‘",$string);
  179. $string=str_replace(""","“",$string);
  180. return $string;
  181. }
  182. //这里还有一堆方法用于检测输入的数据是否合法,到时加入,先写一个
  183. function chkTel($strPhoneNumber) //Check Telphone number
  184. {
  185. If (strspn($strPhoneNumber,"0123456789-"))
  186.   {
  187.    $errinfo[] = "Telphone number input error.";
  188.    $checkpass = False;
  189.   }
  190. }
  191. function chkStrIsNull($chkStr,$strName) //Check Telphone number
  192. {
  193. If (!strLen($chkStr)>0)
  194.   {
  195.    $this->errinfo[] = $strName."不能为空.";
  196.    $this->checkpass = False;
  197.   }
  198. }
  199. }
  200. ?>
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。

[转帖]冰冰通用函数整理主题(updata 12/29/2003)

  1. 最初由 萧木 发表
  2. function enStr($msg) {
  3. $badwords="我靠|我操|shit|SHIT|傻B|TMD";
  4. $msg=trim($msg);
  5. $msg=htmlspecialchars($msg);
  6. //$msg=addSlashes("$msg");
  7. $msg=str_replace("r","",$msg);
  8. $msg=str_replace("n","
  9. ",$msg);
  10. $badlist=explode("|",$badwords);
  11. $nn=count($badlist);
  12. for ($i=0; $i<$nn; $i++) {
  13. $msg=str_replace($badlist[$i],"XXXX",$msg);
  14. }
  15. return $msg;
  16. }
  17. ?>
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。

[转帖]冰冰通用函数整理主题(updata 12/29/2003)

  1. // +-----------------------------------------------------------------------
  2. // | iZz :: File
  3. // +-----------------------------------------------------------------------
  4. // | Copyright &copy; 2000-2002 iZz Studio
  5. // +-----------------------------------------------------------------------
  6. // | This source file is created by iZz Studio. And this file is not
  7. // | public and not a open source file. If you get this file, and not
  8. // | , please contact us by emailing to [EMAIL=justdn@justdn.com]justdn@justdn.com[/EMAIL].
  9. // |      
  10. // |                                                                       
  11. // |                                                                       
  12. // |                                                                       
  13. // |                                                                       
  14. // +-----------------------------------------------------------------------
  15. // | Author(s):                                                            
  16. // |                                                                       
  17. // |                                                                       
  18. // +-----------------------------------------------------------------------
  19. //
  20. // $Id: iZzFile.php,v 1.1 2002/10/31 11:16:21 Beijing Time Zone $
  21. //-------------------------------------------------------------------------
  22. //
  23. //使用方法:
  24. //只读:$ifile = new iFile('test.txt','r');
  25. //读写:$ifile = new iFile('test.txt','w');
  26. //快读:$ifile = new iFile('test.txt','dr');
  27. //快写:$ifile = new iFile('test.txt','w','测试一下咯');
  28. //读取文件内容:$ifile->getFileData();
  29. //显示读取/快读数据:echo $ifile->Data;
  30. //写入文件内容:$ifile->WriteFile('测试一下咯',3);
  31. //关闭文件句柄:$ifile->ColseFile();
  32. //
  33. //注意:写入/快写后自动关闭文件句柄.
  34. //-------------------------------------------------------------------------
  35. class iFile {
  36. var $Fp;
  37. var $Pipe; //(fopen,popen)(f,p)
  38. var $File;
  39. var $OpenMode; //(r,r+,w,w+,a,a+,B)
  40. var $Data;
  41. function iFile($File,$Mode = 'r',$Data4Write='',$Pipe = 'f'){
  42. $this -> File = $File;
  43. $this -> Pipe = $Pipe;
  44. if($Mode == 'dr'){
  45.   $this -> OpenMode = 'r';
  46.   $this -> OpenFile();
  47.   $this -> getFileData();
  48. }else{
  49.   $this -> OpenMode = $Mode;
  50.   $this -> OpenFile();
  51. }
  52. if($this->OpenMode=='w'&&$Data4Write!=''){
  53.   $this -> WriteFile($Data4Write,$Mode = 3);
  54. }
  55. }
  56. function OpenFile(){
  57. if ($this -> OpenMode == 'r'||$this -> OpenMode == 'r+'){
  58.   if($this->CheckFile()){
  59.    if ($this -> Pipe == 'f') {
  60.     $this->Fp = fopen($this -> File, $this -> OpenMode);
  61.    } elseif ($Pipe == 'p') {
  62.     $this->Fp = popen($this -> File, $this -> OpenMode);
  63.    }else{
  64.     Die("Check The OpenFile Pipe,It can be 'f' or 'p'./请检查文件打开参数3,f:fopen(),p:poen().");
  65.    }
  66.   } else {
  67.    Die("Access Error: Check $File is exist./文件访问错误,请检查文件是否存在!");
  68.   }
  69. } else {
  70.   if ($this -> Pipe == 'f') {
  71.    $this->Fp = fopen($this -> File, $this -> OpenMode);
  72.   } elseif ($Pipe == 'p') {
  73.    $this->Fp = popen($this -> File, $this -> OpenMode);
  74.   } else {
  75.    Die("Check The OpenFile Pipe,It can be 'f' or 'p'./请检查文件打开参数3,f:fopen(),p:poen().");
  76.   }
  77. }
  78. }
  79. function CloseFile(){
  80. if ($this->Pipe == 'f'){
  81.   @fclose($this->Fp);
  82. } else {
  83.   @pclose($this->Fp);
  84. }
  85. }
  86. function getFileData(){
  87. @flock($this->Fp, 1);
  88. $Content = fread($this->Fp, filesize($this->File));
  89. $this->Data = $Content;
  90. }
  91. function CheckFile(){
  92. if (file_exists($this -> File)) { return true; } else { return false; }
  93. }
  94. function WriteFile($Data4Write,$Mode = 3){
  95. @flock($this->Fp,$Mode);
  96. fwrite($this->Fp,$Data4Write);
  97. $this->CloseFile();
  98. return true;
  99. }
  100. }
复制代码

                     我是一个呼吸着现在的空气而生活在过去的人
               这样的注定孤独,孤独的身处闹市却犹如置身于荒漠
                                     我已习惯了孤独,爱上孤独
                                 他让我看清了自我,还原了自我
                             让我再静静的沉思中得到快乐和满足
                                   再孤独的世界里我一遍又一遍
                                   不厌其烦的改写着自己的过去
                                             延伸到现在与未来
                                       然而那只是泡沫般的美梦
                                 产生的时刻又伴随着破灭的到来
                         在灰飞烟灭的瞬间我看到的是过程的美丽
                                      而不是结果的悲哀。。。
返回列表