首頁  >  文章  >  後端開發  >  PHP文字操作類別_PHP教程

PHP文字操作類別_PHP教程

WBOY
WBOY原創
2016-07-21 16:00:521254瀏覽

複製程式碼 程式碼如下:
class CtbClass {   

           var     var  $index;       

       //建立一個檔案並寫入輸入               {                       
                       flock($f,LOCK_EX);      fputs($f,$new);           
                       fclose($f);            //  新增資料記錄至檔案末端   
           function  add_write($new)                 $f=fopen($this->file,"a" );           
                                  fputs($f,$new);             
       
           }     
           //  使用,把一行資料轉換為一維數組   
           function  make_array($line)  {     $array  =  explode("x0E",$line);   
                    }   

           //把為一維數組轉換一行數據   
           function  join_array($line)  {   
                       $array  =  join("x0E",$line);   
                       return  $array;   
           }
           //  返回數據文件的總行數   
           function  getlines()  {   
                       $f=file($this->file);           
                       return  count($f);           
           }   
           //  返回下一行的數據記錄(備用)   
           function  next_line()  {   
                       $this->index=$this->index ;           
                       return  $this->get();           
}   

           //  返回上一行的數據記錄(備用)   
           function  prev_line()  {   
                       $this->index=$this->index--;           
                       return  $this- >get();           
           }        >           function  get()  {   
             
                       flock($f,LOCK_SH);     ($i=0;$iindex;$i )  {   
                            
                       }    
       
                       fclose($f);     return  $line;           
           }
           //  與現有行程的資料記錄資料較大   
                         $f=fopen($this->file,"r");            $f,LOCK_SH );   
                       for($i=0;$i                       $$問題=explode("x0E",$rec);   
                                return  $line;           
          開啟資料檔---以一維數組返回文件內容
           function  read_file()  {   
         this  {   
                                               }   
           🎜>           }
           //  開啟資料檔案---                 if  (file_exists($this->file))  {                $f  =file($ this->file);   
                                   $lines  =  array();   
                                   foreach  ($f  as  $rawline)  {   
                                               $tmpline  =  explode("x0E",$rawline);   
                                               array_push($  $tmpline);   
                                        }   
                    }   
           //  傳入一個陣列,合併成一行資料,重寫整個檔案   $array){   
                       $newline  =  implode("x0E",$array);               
                       $f  =  fopen($this->file,"w");   
                       flock($f,LOCK_EX);
                       fputs($f,$newline);      close($f);   
           }

           //  與在文件末端中新增   
        
                       $s=implode("x0E",$                $ f=fopen($this->file,"a");           
                                  fputs($f,$s);             ($check_n==1)  fputs ($f,"n");           
                      }           

           //  array)  {   
                       $newfile  =  implode("x00E",$arra      $f  =  fopen($this->file,"r");   
                                 while  ($問題  =  fgets($f,1024))  {   
                  $line;   
                       }    ose($f);   
                       $f  =  fopen($this->file,"w ");   
                       flock($f,LOCK_      fputs($f,$newfile);   
                     

           //  更新上位符合條件的資料記錄,適用於每行位元組資料較大的情況   
    {   
                        ("x0E",$update_array);         
                       $newfile  =  "";               
                       $fc=file($this->file);   
                       $f=fopen($this->file,"r" );   
                       flock($f,LOCK_      for  ($i=0;$i             =  explode("x0E",$fc [$i]);   {   
                              .chop($fc[$i])."n";   
                       約  {   
                          =  $newfile.$update_string;   
                                         }   
                               $f=fopen($this->file,"w");
                       flock($f,LOCK_EX);     puts($f,$newfile);   
                       

           //  更新上位符合條件的資料記錄,適用於每行位元組資料較小的情況   )  {   
                       $newline  =  impdedede ("x0E",$update_array);         
                                   $f  =  fopen($this->file,"r");   ,LOCK_SH);   
                       while  ($line  =  fgets($f,1024)))                        $tmpLine  =  explode("x0E",$1                if  ($tmpLine[$column]  ==  $query_string)  {   
                                    >                                                                                         }   
                            fclose($f);   
         this->file,"w");   
                               fputs($f,$newfile);   
                   }

           //  刪除所有符合條件下的資料記錄,適用於每行位元組資料較大的情況    
                       $newfile  =      🎜>                       $fc=file($this->file);      f=fopen($this->file,"r");   
                               for  ($ i=0;$i                   ",$fc[$i]);   
                          $query_string)  {   
                          =  $newfile.chop($fc[$i])."n";   
                                        }   
        >                       $f= fopen($this->file,"w");   
                                 fputs($f,$newfile);   
                   }

           //  刪除所有符合條件的資料記錄,適用於每行位元組資料較少的情況   
       
                       $newfile  =   🎜>                       $f  =  fopen($this->file,       flock($f,LOCK_SH);      flock($f,LOCK_SH);   
                   
                                 tmpLine  =  explode("x0E",$line);   
                lumn]  !=  $query_string)  {   與
                      $newfile  .=  $line;   
                                        }   
fclose($f);   
                       ),             flock($f,LOCK_EX);   
            >                       fclose($f);   
    /取得某一文件裡某一字段的最大值   
           function  get_max_value($column)  {    $tlines  =  file($this- >file);   
                       for  ($i=0                           $line=explode("x0E",$tlines[$i])  $line=explode("x0E",$tlines[$i])  $line=explode("x0E",$tlines[$i]) >                                               }
               $get_max_value  =  max($get_value);    $get_max_value;   
           }   

    維數組回傳所有符合條件的資料   
           function  select($column,  $query_string)        $tline  =  $this->openfile();   
                                    foreach  ( $tline  as  $line)  {   
                     $query_string)  {   
                    _push($lines,  $line);   
                                        }   

return  $lines;   
           }

           //  作用與function  select()相同時速可能略有提升   
   {   
                       if  (file)) 🎜>                                                               foreach  ($                                                                          column]  ==  $query_string)  {   
                                                           $lines[]=$tmpLine;   
                                               }   
                                   }   
                       }   

                       return  $lines;   
           }

           //  使用中對中關於資料檔案是否包含$query_string查詢,以一維陣列傳回第一個符合條件的資料 $query_string)  {   
$tline  =  $this->read_file();   
                                                                                   if  ($line[$column] ==  $query_string)  {   
                     
                                                                 }      
           }
           //  選擇下一個/上一個行(next_prev  ==>  1/下一個,      _next_prev_line($column,  $query_string,  $next_prev)  {   
           =  $this ->read_file();   
                                           $line_key  =  -1;          as  $tmpLine)  {   
                     
                                                                  
                               ==  $query_string)  {   
                                  if  ($line_key  ==  0)  {   
                                                                            else  {   
                                                                                  >                                    
                                 >                                 地  =  $line;   
                        
                                  next_prev  ==  2)  {    //  上一個?   
                               ==  $query_string)  {   
                                  if  ($line_key  ==  $line_key_end)  {                                                                               否則  {   
                                                                       $line_key_down  =  $line_key     1;   
                                                                        休息;   
                                                         }   
                                                }   
                                   }  其他  {   
                                                 返回0;   
                                  }   
                     }   
                       $down_line =  $this->make _array($tline[$line_key_down]);   
                     }   

   
}  
? > 

http://www.bkjia.com/PHPjc/317060.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317060.htmlTechArticle複製程式碼如下: ?php classCtbClass{ var$file; var$索引; //建立一個檔案並讀取輸入functionnull_write($new) { $f=fopen($this-file,"w");羊群($f,LOCK_EX); fput...
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn