給你舉個很簡單的例子,如下:
十載建站經(jīng)驗, 網(wǎng)站制作、做網(wǎng)站客戶的見證與正確選擇。創(chuàng)新互聯(lián)提供完善的營銷型網(wǎng)頁建站明細報價表。后期開發(fā)更加便捷高效,我們致力于追求更美、更快、更規(guī)范。
form method="post"
input type="text" name="user" /
input type="text" name="pass" /
input type="submit" name="Submit" value="提交" /
/form
?php
/*寫入*/
if ($_POST[Submit]) {
$fp=fopen("db.txt","a");
fwrite($fp,$_POST[user]."|".$_POST[pass]."\r\n"); //寫入數(shù)據(jù),中間用|隔開
fclose($fp);
}
/*讀取,可以通過|拆分項*/
$lines=file("db.txt");
print_r("pre");
print_r($files);
/*刪除*/
你可以用一項來做標識,比如提交時間,來定位行數(shù)。
?
文本:
優(yōu)點:讀取速度快。不需要數(shù)據(jù)庫。
缺點:
檢索極不方便。幾乎不可能。更別提復(fù)雜的檢索了。
排序不方便。
單個文本數(shù)據(jù)過大時一次讀入會占用大量內(nèi)存
所以不能存儲大量數(shù)據(jù)
數(shù)據(jù)安全性等于0。
數(shù)據(jù)庫的優(yōu)點就是 文本的缺點。
我建議一下吧,文本數(shù)據(jù)庫的例子本來太多,但是為了邏輯簡化,最好通過專門接口實現(xiàn)文件與數(shù)據(jù)的轉(zhuǎn)換,可以采用我下面的模板編寫:
?php
//文件最前面定義兩個全局變量,數(shù)據(jù)庫文件名和用戶數(shù)組
$pwd_db_file='db.txt';
$UserPassword=array();
//下面的pwd_db_read函數(shù),把文件內(nèi)容讀入到全局數(shù)組中
function pwd_db_read(){
global $pwd_db_file, $UserPassword;
$fp=fopen($pwd_db_file,'r');
while ($s=fgets($fp)){
list($usr,$pwd)=explode('|', $s);
$UserPassword[$usr]=$pwd;
}
fclose($fp);
}
//下面的pwd_db_write函數(shù)保存數(shù)組內(nèi)容到文件中
function pwd_db_write(){
global $pwd_db_file, $UserPassword;
fp=fopen($pwd_db_file, 'w');
foreach ($UserPassword as $usr=$pwd)
fputs($fp,"$usr|$pwd\n");
fclose($fp);
}
//有了上面的全局變量和函數(shù),要寫什么功能都簡單
//下面假釋本腳本調(diào)用的時候通過reg.php?job=adduser=...pass=...
//的格式進行調(diào)用,job為add表示添加用戶,del表示刪除,modi表示修改
//另外的user和pass表示用戶名或者密碼,job不是以上內(nèi)容表示登錄
//主程序一開始就打開數(shù)據(jù)庫
pwd_db_read();
//下面判斷功能
if ($jon=='add'){
if (array_key_exists($user,$UserPassword)) echo "用戶 $user 已經(jīng)存在!"
else $UserPassword[$user]=$pass;//就一句話,簡單吧
}elseif (job=='del'){
unset($UserPassword[$user]);//你自己考慮編寫是否確認刪除的內(nèi)容
}elseif ($job=='modi'){
if (array_key_exists($user,$UserPassword)) $UserPassword[$user]=$pass;//和添加是不是有點類似
else echo "用戶 $user 不存在!"
}else{
if ($UserPassword[$user]==$pass){
echo '密碼正確。';
//接下來可能要做許多事情
}else echo '密碼錯誤!';
}
//程序最后保存數(shù)據(jù)庫修改
pwd_db_write();
?
看得懂嗎,沒有上機調(diào)試,語法問題可能難免,如果發(fā)現(xiàn)不明白的問題請補充。
PHP文本數(shù)據(jù)庫的搜索方法
searchstr=("/".preg_quote($searchstr)."/");
//$searchstr是查找的關(guān)鍵字
$records=file($file);//獲取所有的記錄數(shù)
//$file是查找的數(shù)據(jù)文件
$search_reocrds=preg_grep
($searchstr,
$records);//開始查找記錄
//$search_reocrds為查找到的記錄數(shù)
unset($records);
if($search_records){
//開始顯示記錄,寫下你自己的處理程序********************
while
(list
($key,
$val)
=
each
(
$search_records))
{
echo
"$val
";
}
//****************************************************
}
網(wǎng)頁題目:文本數(shù)據(jù)庫php,文本數(shù)據(jù)庫 分隔符
瀏覽地址:http://sd-ha.com/article44/hooiee.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、定制網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、服務(wù)器托管、網(wǎng)站導(dǎo)航、手機網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)