所以,我有的新方法是這一次,希望它會正常工作對您
文件名爲爲例:subscribes.txt(我用一個「」 delimitor,你可以改變它,因爲它適合你)
; a comment line
43,1404399704
75,1404406800
104,1404399200
6,1404399500
而且小腳本
$file = 'subscribes.txt';
$delim= ','; // set the delimitor of your cols
$time = time(); // get time to use it in all the script
// this part is to get the last month number of days
$y = date('Y'); // year
$lm = date('n') - 1; // last month
$y = ($lm == 0) ? $y - 1 : $y; // if we are in jan., year - 1
$lm = ($lm == 0) ? 12 : $lm; // if we are in jan., last month was dec.
$lm = mktime(0, 0, 0, $lm, 1, $y); // so, the last month
$lm_days = intval(date("t",$lm)); // get the number of days in last month
// you can get the current month number of days with :
// $lm_days = intval(date('t'));
// end of the part
$file = file_get_contents($file); // read file content
$file = explode(PHP_EOL, $file); // transform it in array
foreach($file as $lk => $line){
if(!empty($line) && !preg_match('/^;(.*)/', $line)){ // if line not empty and don't start with ;
$cid= null;
$st = null;
list($cid,$st) = explode($delim, trim($line)); // explode the 3 cols of the line
$st = $st + 3600*24*$lm_days;
if($time >= $st){
// send notifications etc etc ... (eg: your script)
}
else{
// else we will delete the line to light the file
unset($file[$lk]);
}
}
}
// once done, letz write the lighted file
$file = implode(PHP_EOL, $file); // convert array to string
file_put_contents($file, $file); // put it back in the file
而當你想添加一個訂閱,你只需要運行這個
$file_name = 'subscribes.txt';
$delim= ','; // set the delimitor of your cols
$time = time(); // get time to use it in all the script
$file = file_get_contents($file_name); // read file content
$file = explode(PHP_EOL, $file); // transform it in array
$file[] = $cid.$delim.time(); // add to array a new entry
// there you can add multiple entries, let it fit to you :P
$file = implode(PHP_EOL, $file); // convert array to string
file_put_contents($file, $file); // put it back in the file
告訴我,如果它仍然掛起或什麼的,我會盡力去找其他的解決方案:)
我懷疑'WWW。 abcde.com/expiration.txt'是您的服務器上的有效本地相對路徑,您需要將該方案預先寫入:http:// www.abcde.com/expiration.txt。請勿將內容放在遠程網站上,請記住。爲什麼不使用數據庫而不是文本文件? – DanFromGermany
嗨。感謝您的答覆。我無法使用客戶端數據庫。我只從中獲取數據並使用它發送消息。遠程網站是我自己公司的網站,它將託管不同客戶的許可證到期細節。 – user2443689