2012-03-11 12 views
2

誰かが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> 

答えて

2

私はICS-Parserをお勧めします。

ICSをループして好きなように印刷することができるアレイにICSを変換することは非常にうまくいきます。その例はウェブサイトにあります。

+0

を掲載しますそれを見つける場合-parser/downloads/list)は、「このプロジェクトには現在ダウンロードがありません」と表示されます。 –

+0

ここでファイルをクリックしてください:http://code.google.com/p/ics-parser/source/browse/#svn%2Ftrunk - 「生のファイルを表示する」を選択してください – 472084

+1

ありがとうございます。私はそれが働いて、それは本当に良いように見えますが、それがアクセスされる日(今日)に起こっていることだけを表示するためにそれを変更する方法はありますか? (私はすでに質問に載っているものをここに置くには大きすぎるので入れます) –

3

あなたはREADまたはWRITEする必要がありますか? は、読み取りのために私が過去に使用:

http://sevengoslings.net/icalendar

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

http://sourceforge.net/projects/phpicalendar/から<を私はこの1つはまた読むことができると信じていますが、それは巨大です - あなただけの機能がかかる場合がありますまたはそこから2つを選択してください

しかし、あなたの質問では、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 
} 
?> 

、その後、タグに人間readebleフォーマットを与えることを正規表現または何か他のものを使用して..私

EDIT:

は、私はちょうど私が前に使用する関数を見つけました: それは使用していますこのクラス:http://www.kigkonsult.se/iCalcreator/index.php それは私によって書かれていませんでしたが、それは過去に私のために働いていました。 私は、この関数のソースを覚えていない - 私は私が原因ダウンロードに(http://code.google.com/p/ics私は、それをダウンロードするにはどうすればよい...

<?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"; 

      ?> 
関連する問題