Copy code The code is as follows:
class CtbClass { file and write input
function null_write ($new)
{
$f=fopen($this->file,"w");
LOCK_EX);
fputs($f,$new) ; add_write($new) { "a"); Back to use together, convert a line of data into a one -dimensional array
Function Make_array ($ LINE) {
$ array = Explode ("x0e", $ line);
Return $ array;
}
//Convert a row of data into a one-dimensional array
function join_array($line) {
$array = join("x0E",$line);
🎜> }
// The number of head lines returned to the data file
Function Getlines () {
$ F = File ($ this- & gt; file);
Return Count ($ f); 🎜>
; function get() {
$f=fopen($this-> ;file,"r");
Flock($f,LOCK_SH);
$rec= fgets($f,1024); fclose($f);
flock($f, LOCK_SH);
for($i=0;$i<=$this->index;$i++) {
$rec=fgets($f, 1024*5);
> $line=explode("x0E",$rec); File content $line $line;
}
🎜> $this->file);
foreach ($f as $ rawline) { array_push ($lines, $tmpline); turn $lines;
overwrite($array){ ;file,"w"); LOCK_EX);
fputs($f,$newline);
fclose($f);
fputs($f,$newline);
// Add a row of data records to the end of the file
function add_line($array,$check_n=1) {
$s=implode("x0E ",$array);
f=fopen($this->file,"a"); fputs($f,"n"); Data is recorded to the front of the file flock($f,LOCK_SH); ($line = fgets($f,1024)) { fclose($f);
$f = fopen($this->file , "w"); fclose($f);
}
$update_string = implode ("x0E",$update_array); ; r");
flock($f,LOCK_SH);
for ($i=0;$i $list = explode("x0E", $fc[$i]); $newfile >} Else {
$ newfile = $ newfile. $ Update_string;
}
}
FCLOSE ($ f);
$ f = FOPEN ($ this- & gt; file, "w ");
flock($f,LOCK_EX);
fputs($f,$newfile);
fclose($f);
}
$newline = implode ("x0E",$update_array);
flock($f,LOCK_SH); < ~ ; F> $ newfile. = $ Newline;
} else {
$ newfile. = $ Line;
}
}
fclose ($ f);
$ f = FOPEN ( $this->file,"w");
""; 🎜> $fc=file($this->file); flock($f,LOCK_SH);
for ($i=0;$i FLOCK ($ f, lock_ex);
fputs ($ f, $ newfile);
fclose ($ f);
}
= "";
$f ($line $tmpLine = explode("x0E",$line);
f,LOCK_EX);
) { this->file);
for ($i=0;$i<=count($tlines);$i++) {
$line=explode("x 0E",$tlines[$i]) ;
$ get_max_value = max ($ get_value);
Return $ get_max_value;
}
// Whether a field of the data file contains $ query_string to query, two Dimensional array returns all data that meets the conditions $lines = array();
foreach ($tline as $line) { array_push($lines, 🎜 >
// The function is the same as function select(), the speed may be slightly improved.
function select2($column, $query_string) {
if (file_ exists($this->file)) {
$tline ine) { If ($ line[$column] == $query_string) { 🎜> return $lines;
}
> // Whether a field of the data file contains $ Query_String to query, and return the first data with a one -dimensional array
Function Select_line ($ COLUMN, $ Queery_String) {
$tline = $this->read_file();
foreach ($tline as $tmpLine) {
$line = $this->make_array($tmpLine);
column] == $query_string) { break;
// select next/prev line(next_prev ==> 1/next, 2/prev) by cx
function select_next_prev_line($column, $query_string, $next_prev) {
$tline = $this->read_file();
$line_key_end = count($tline) - 1;
$line_key = -1;
foreach ($tline as $tmpLine) {
$line_key++;
$line = $this->make_array($tmpLine);
if ($next_prev == 1) { // next?
if ($line[$column] == $query_string) {
if ($line_key == 0) {
return 0;
} else {
$line_key_up = $line_key - 1;
return $up_line;
}
} else {
$up_line = $line;
}
} elseif ($next_prev == 2) { // prev?
if ($line[$column] == $query_string) {
if ($line_key == $line_key_end) {
return 0;
} else {
$line_key_down = $line_key + 1;
break;
}
}
} else {
return 0;
}
}
$down_line = $this->make_array($tline[$line_key_down]);
return $down_line;
}
}
?>
http://www.bkjia.com/PHPjc/317060.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/317060.htmlTechArticle复制代码 代码如下: ?php classCtbClass{ var$file; var$index; //建立一个文件并写入输入 functionnull_write($new) { $f=fopen($this-file,"w"); flock($f,LOCK_EX); fput...