簡體   English   中英

PHP:以純文本格式輸出iCalendar文件

[英]PHP : Output iCalendar File as Plain Text

有人可以推薦腳本/一些代碼來獲取iCalendar日歷文件並以純文本格式輸出當天的事件嗎?

當前代碼

<?php
/**
 * This example demonstrates how the Ics-Parser should be used.
 *
 * PHP Version 5
 *
 * @category Example
 * @package  Ics-parser
 * @author   Martin Thoma <info@martin-thoma.de>
 * @license  http://www.opensource.org/licenses/mit-license.php  MIT License
 * @version  SVN: <svn_id>
 * @link     http://code.google.com/p/ics-parser/
 * @example  $ical = new ical('MyCal.ics');
 *           print_r( $ical->get_event_array() );
 */
require 'class.iCalReader.php';

$ical   = new ICal('THE URL');
$events = $ical->events();

$date = $events[0]['DTSTART'];
foreach ($events as $event) {
    echo "".$event['SUMMARY']."<br/>";
}
?>

<style>
body
{
    font-family: Segan;
}
</style>

您需要讀還是寫? 閱讀我過去使用的內容:

http://sevengoslings.net/icalendar

http://www.phpclasses.org/browse/file/16660.html

http://sourceforge.net/projects/phpicalendar/- <我相信這也可以閱讀,但是它很大-您可能只是從那里取一兩個函數

但是-通過您的問題,我理解您需要閱讀-iCalender IS純文本。 您只需要打開文件並逐行繪制。

<?php
 $data = file_get_contents("myfile.ics"); //read the file
$convert = explode("\n", $data); //create array separate by new line

for ($i=0;$i<count($convert);$i++)  
 {
     echo $convert[$i].', '; //write value by index
}
?>

然后使用正則表達式或其他方式為標簽提供可讀格式。

編輯我:

我剛剛找到了以前使用過的函數:它使用了此類: http : //www.kigkonsult.se/iCalcreator/index.php它不是我編寫的,但是過去對我有用。 我不記得此功能的來源-如果找到它,我將發布..

   <?php

            require_once 'iCalcreator/iCalcreator.class.php';

              $filename = 'D:\Document\Docs\2007\05\iCal-20070508-082112.ics';

              $v = new vcalendar(); // initiate new CALENDAR
              $v->parse($filename);

              # get first vevent
              $comp = $v->getComponent("VEVENT");

              #print_r($comp);
              $summary_array = $comp->getProperty("summary", 1, TRUE);
              echo "summary: ", $summary_array["value"], "\n";

              $dtstart_array = $comp->getProperty("dtstart", 1, TRUE);
              $dtstart = $dtstart_array["value"];
              $startDate = "{$dtstart["year"]}-{$dtstart["month"]}-{$dtstart["day"]}";
              $startTime = "{$dtstart["hour"]}:{$dtstart["min"]}:{$dtstart["sec"]}";

              $dtend_array = $comp->getProperty("dtend", 1, TRUE);
              $dtend = $dtend_array["value"];
              $endDate = "{$dtend["year"]}-{$dtend["month"]}-{$dtend["day"]}";
              $endTime = "{$dtend["hour"]}:{$dtend["min"]}:{$dtend["sec"]}";

              echo "start: ",  $startDate,"T",$startTime, "\n";
              echo "end: ",  $endDate,"T",$endTime, "\n";

            ?>

我推薦ICS-Parser

將ICS轉換成可以循環瀏覽並打印所需格式的數組的工作非常出色,例如在其網站上。

采用

[英]Use <?php as plain text in a .php file?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM