日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > php >内容正文

php

php文本教学,php中文本操作的类

發(fā)布時間:2024/10/14 php 66 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php文本教学,php中文本操作的类 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

給大家一個簡單的文本操作的類。

我以前寫的,不過一直都沒機(jī)會用了,文本不如數(shù)據(jù)庫。數(shù)據(jù)是以行保存的,以\n結(jié)尾,注意你輸入的數(shù)據(jù)必須以"\n"結(jié)尾的,這是幾個最基本的類成員,文本的特別要注意效率問題,比如你要更新文件的2,3,4行,用:

for($i=2;$i<=4;$i++)$this->update($file,$i,$msg);不如這樣的:

$data=$this->read($file);

for($i=2;$i<=4;$i++)$data[$i]=$msg;

$this->write($file,$data); 的

復(fù)制代碼 代碼如下:

class text{

var $key="<?die ;?>"; //數(shù)據(jù)保護(hù)

var $keylen; //數(shù)據(jù)保護(hù)長度

function text() //類的構(gòu)造器

{

$this->keylen=strlen($this->lkeylen); //得到保護(hù)長度

}

function read($file) //讀文件,返回一個數(shù)組

{

if(file_exists($file)):

$data=@file($file);

$data[0]=substr($data[0],$this->keylen);

return $a;

endif;

}

function write($file,$data=array()) //寫文件,數(shù)據(jù)為一個數(shù)組

{

if($fp=fopen($file,"w")):

flock($fp,3);

fwrite($fp,$this->key);

foeach($data as $v)fwrite($fp,$v);

return true;

endif;

}

function add($file,$msg)

//向文件最后添加數(shù)據(jù)(不存在就先建立文件)

{

$a=$this->read($file); //這個不管文件存在不

$a[]=$msg;

return $this->write($file,$a);

}

function insert($file,$n,$msg) //向第$n前插入數(shù)據(jù)

{

if($a=$this->read($file)):

$a[$n]=$msg.$a[$n];

return true;

endif;

}

function updata($file,$n,$msg) //更新$n數(shù)據(jù)

{

if($a=$this->read($file)):

$a[$n]=$msg;

return true;

endif

}

function del($file,$n) //刪除$n數(shù)據(jù)

{

return $this->updata($file,$n,"");

}

}

總結(jié)

以上是生活随笔為你收集整理的php文本教学,php中文本操作的类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。