PHP:以纯文本形式输出iCalendar文件
问题描述:
任何人都可以推荐一个脚本/一些代码来获取iCalendar日历文件并以纯文本形式输出当天的事件吗?PHP:以纯文本形式输出iCalendar文件
目前代码
<?php
/**
* This example demonstrates how the Ics-Parser should be used.
*
* PHP Version 5
*
* @category Example
* @package Ics-parser
* @author Martin Thoma <[email protected]>
* @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是纯文本。 您只需要打开文件并逐行绘制。
<?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
}
?>
,然后使用正则表达式或别的东西,给人类readeble格式标签..
编辑我:
我刚刚发现我使用的函数之前:它使用 这个课程: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";
?>
如何下载它,因为下载(http://code.google.com/p/ics -parser/downloads/list)它只是说'这个项目目前没有下载。'? – 2012-03-11 12:34:07
点击此处的文件:http://code.google.com/p/ics-parser/source/browse/#svn%2Ftrunk - 然后选择'查看原始文件' – 472084 2012-03-11 12:55:24
谢谢。我有它的工作,它看起来非常好,但我怎么能改变它只显示它被访问的一天(今天)发生的事情? (我把我已经得到的问题,因为它太大,不能放在这里) – 2012-03-11 13:05:17