我需要在我的網站上創建最後登錄的成員列表,但我不想要用戶MySQL。我做了一些搜索在計算器和谷歌寫了這樣的代碼:用PHP設置文本文件中添加內容的限制
////////////CHECK LIMIT
$storage = "engine/data/write.txt";
$readz = file_get_contents($storage);
$listz = explode('|||',$readz);
$counter = count($listz);
if($counter > "3"){
$stop = "1";
}else{
$stop = "0";
}
if($stop == "0"){
///REMOVE MEMBER IF AVAILABLE
if (preg_match("<!-- UserID: {$member_id} -->", $readz)){
$content = file_get_contents($storage);
$content = str_replace("<!-- UserID: {$member_id} -->".$user."|||", '', $content);
file_put_contents($storage, $content);
}
//ADD MEMBER AGAIN
if (!preg_match("<!-- UserID: {$member_id} -->", $readz)){
$beonline_file = fopen($storage, "a+");
fwrite($beonline_file, "<!-- UserID: {$member_id} -->".$user."|||");
fclose($beonline_file);
}
}
問題是我不能設置限制!我如何編輯此代碼來設置限制,僅在文本文件中添加用戶?
ü希望當限額達到20 – DevZer0
20後,我想刪除文本文件的第一行和最後一行添加最後一個成員做什麼! – Alireza
確定首先你只創建1行。其次是你的'preg_match'工作,因爲我沒有看到你的正則表達式有'「/../」' – DevZer0