php到日历ics脚本几乎可以正常工作。。?

php到日历ics脚本几乎可以正常工作。。?,php,calendar,icalendar,Php,Calendar,Icalendar,我正在使用我找到的这个php-ics脚本。不久前,我为一些客户开发了活动日历。他们想要一种方法将其导出到.ics、谷歌 这是我的delima,我想。。我不确定您是否需要$start\u date、$start\u time、$end\u date、$end\u time。。我的MYSQL数据库中没有这些。。。那么我是不是应该把这些都留空白 我只有一个$date字段,我输入的日期如下:“0000-00-00” 下面是写入文件的简单php脚本:(这里是ics部分) 如您所见,我使用$date行来

我正在使用我找到的这个php-ics脚本。不久前,我为一些客户开发了活动日历。他们想要一种方法将其导出到.ics、谷歌

这是我的delima,我想。。我不确定您是否需要$start\u date、$start\u time、$end\u date、$end\u time。。我的MYSQL数据库中没有这些。。。那么我是不是应该把这些都留空白

我只有一个$date字段,我输入的日期如下:“0000-00-00”

下面是写入文件的简单php脚本:(这里是ics部分)


如您所见,我使用$date行来等于这些ics变量:$start_date、$start_time、$end_date、$end_time。。不确定这是否可以


谢谢你的帮助。。我是这方面的新手。

可能会有所帮助。谢谢,我在搜索时看到了第一个链接,但仍然是空的。我将阅读你的第二个链接。感谢您的关注。如果您正在以缩写形式“0000-00-00”存储日期,那么您需要将所有时间默认为0:00或类似的时间,因为您不存储它。
<?php
$ics_contents  = "BEGIN:VCALENDAR\n";
$ics_contents .= "VERSION:2.0\n";
$ics_contents .= "PRODID:PHP\n";
$ics_contents .= "METHOD:PUBLISH\n";
$ics_contents .= "X-WR-CALNAME:Schedule\n";

# Change the timezone as well daylight settings if need be
$ics_contents .= "X-WR-TIMEZONE:America/New_York\n";
$ics_contents .= "BEGIN:VTIMEZONE\n";
$ics_contents .= "TZID:America/New_York\n";
$ics_contents .= "BEGIN:DAYLIGHT\n";
$ics_contents .= "TZOFFSETFROM:-0500\n";
$ics_contents .= "TZOFFSETTO:-0400\n";
$ics_contents .= "DTSTART:20070311T020000\n";
$ics_contents .= "RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\n";
$ics_contents .= "TZNAME:EDT\n";
$ics_contents .= "END:DAYLIGHT\n";
$ics_contents .= "BEGIN:STANDARD\n";
$ics_contents .= "TZOFFSETFROM:-0400\n";
$ics_contents .= "TZOFFSETTO:-0500\n";
$ics_contents .= "DTSTART:20071104T020000\n";
$ics_contents .= "RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\n";
$ics_contents .= "TZNAME:EST\n";
$ics_contents .= "END:STANDARD\n";
$ics_contents .= "END:VTIMEZONE\n";
?>
<?php
while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) {
  $id            = $row_Recordset1['id'];
  $start_date    = $row_Recordset1['date'];
  $start_time    = $row_Recordset1['date'];
  $end_date      = $row_Recordset1['date'];
  $end_time      = $row_Recordset1['date'];
  $category      = $row_Recordset1['event_type1'];
  $name          = $row_Recordset1['event_name'];
  $location      = $row_Recordset1['event_location_name'];
  $description   = $row_Recordset1['comments'];

  # Remove '-' in $start_date and $end_date
  $estart_date   = str_replace("-", "", $start_date);
  $eend_date     = str_replace("-", "", $end_date);

  # Remove ':' in $start_time and $end_time
  $estart_time   = str_replace(":", "", $start_time);
  $eend_time     = str_replace(":", "", $end_time);

  # Replace some HTML tags
  $name          = str_replace("<br>", "\\n",   $name);
  $name          = str_replace("&amp;", "&",    $name);
  $name          = str_replace("&rarr;", "-->", $name);
  $name          = str_replace("&larr;", "<--", $name);
  $name          = str_replace(",", "\\,",      $name);
  $name          = str_replace(";", "\\;",      $name);

  $location      = str_replace("<br>", "\\n",   $location);
  $location      = str_replace("&amp;", "&",    $location);
  $location      = str_replace("&rarr;", "-->", $location);
  $location      = str_replace("&larr;", "<--", $location);
  $location      = str_replace(",", "\\,",      $location);
  $location      = str_replace(";", "\\;",      $location);

  $description   = str_replace("<br>", "\\n",   $description);
  $description   = str_replace("&amp;", "&",    $description);
  $description   = str_replace("&rarr;", "-->", $description);
  $description   = str_replace("&larr;", "<--", $description);
  $description   = str_replace("<em>", "",      $description);
  $description   = str_replace("</em>", "",     $description);

  # Change TZID if need be
  $ics_contents .= "BEGIN:VEVENT\n";
  $ics_contents .= "DTSTART;TZID=America/New_York"     . $estart_date . "T". $estart_time . "\n";
  $ics_contents .= "DTEND:"       . $eend_date . "T". $eend_time . "\n";
  $ics_contents .= "DTSTAMP:"     . date('Ymd') . "T". date('His') . "Z\n";
  $ics_contents .= "LOCATION:"    . $location . "\n";
  $ics_contents .= "DESCRIPTION:" . $description . "\n";
  $ics_contents .= "SUMMARY:"     . $name . "\n";
  $ics_contents .= "UID:"         . $id . "\n";
  $ics_contents .= "SEQUENCE:0\n";
  $ics_contents .= "END:VEVENT\n";
}
?>

<?php
$ics_contents .= "END:VCALENDAR\n";

# File to write the contents
$ics_file   = 'schedule.ics';

if (is_writable($ics_file)) {
  if (!$handle = fopen($ics_file, 'w')) {
     echo "Cannot open file ($ics_file)\n\n";
     exit;
  }

  # Write $ics_contents to opened file
  if (fwrite($handle, $ics_contents) === FALSE) {
    echo "Cannot write to file ($ics_file)\n\n";
    exit;
  }

  # echo "Success, wrote to <b>schedule.ics</b><br>\n\n";

  fclose($handle);

} else {
  echo "The file <b>$ics_file</b> is not writable\n\n";
}
?>