所以,我的新方法就是这个,希望它对你有用
示例文件名为:subscribes.txt(我使用了“,”分隔符,您可以根据需要更改它)
; 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
如果它仍然挂起,请告诉我,我会尝试寻找其他解决方案:)