重复事件php


Recurring events php

我正试图允许用户在类似于谷歌日历的日历应用程序中安排活动。我需要实现每3周重复一次,在2次出现后结束的事件

我当前的代码如下:

$week = array('0'=>"Sunday","1"=>"Monday","2"=>"Tuesday","3"=>"Wednesday","4"=>"Thursday","5"=>"Friday","6"=>"Saturday");
                       $day = $week[$val];
$days = array(
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday',
    'Sunday',
  );
  $today = new DateTime($day);
  //$today = new DateTime('Friday'); //can set specific day if needed
//  print "Today is " . $today->format('l') . "'n";
  foreach($days as $day) {
    $diff = new DateTime($day);
    $diff = $diff->format('N') - $today->format('N');
    if($diff > 0) {
      //print "$day is $diff days in the future'n";
      //print "'n$diff days future'n";
       $st=date('Y-m-d H:i:s',strtotime('+'.($diff).' day',strtotime($s)));
    $et=date('Y-m-d H:i:s',strtotime('+'.$date_diff.'day',strtotime($s)));
    }
    elseif($diff < 0) {
      $diff = abs($diff);
     // print "$day is $diff days in the past'n";
     //  print "$diff days fast'n";
        $st=date('Y-m-d H:i:s',strtotime('+'.($diff).' day',strtotime($s)));
    $et=date('Y-m-d H:i:s',strtotime('+'.$date_diff.'day',strtotime($s)));
    }
    else {
    $st=date('Y-m-d H:i:s',strtotime('+'.$recordsave.' day',strtotime($s)));
    $et=date('Y-m-d H:i:s',strtotime('+'.$date_diff.'day',strtotime($s)));
    }
  }

朋友们,有什么想法吗?

激发PHP代码的唯一方法是如果用户正在访问它。

您可以设置一个CRON计划来运行特定的代码行,方法是在CRON作业中每3周调用一次PHP页面,持续2周。