0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PHPで、XML経由でiCalを生成する

0
Last updated at Posted at 2024-08-06

iCalをPHPで直に書き出そうとすると、PHPのソースコードが複雑化しやすいです。そこで、JSON経由またはXML経由で扱う方法を考えました。JSON経由ではJSONが複雑化するので、XML経由を採用しました。

<?
header('content-type:text/plain');
$vcalendar=new SimpleXMLElement('<VCALENDAR/>');

// $vcalendar内に、XML要素を追加してゆく。
// 「BEGIN:」や「END:」で始まらないプロパティーは、当該要素の属性名にする。
// 「BEGIN:」や「END:」の後に来る文字列は、子XML要素のタグ名にする。

function to_ical($xml){
	echo'BEGIN:'.$xml->getName()."\n";
	foreach($xml->attributes()as$key=>$value){
		echo$key.':'.$value."\n";
	}
	foreach($xml->children()as$child){
		to_ical($child);
	}
	echo'END:'.$xml->getName()."\n";
}
to_ical($vcalendar);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?