[英]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转换成可以循环浏览并打印所需格式的数组的工作非常出色,例如在其网站上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.