我有一个问题,如果有人会这么善良。
实际上这是两个相互依存的问题。
我正在创建一个日历文件,我不习惯编写文件,尽管将它写入.txt文件似乎很简单。
我是否需要为.ics文件编写标题?如果是这样,该怎么做呢?
这有什么不对,无法在iCal(MacOS)中打开?
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTEND: 19700101T024640Z
UID: 5724dce4946da
DTSTAMP:20160430T162716Z
LOCATION:Green Park Station
DESCRIPTION:The Urban Playground Team are the original performance-parkour (2PK) company combining urban & contemporary dance with authentic French Free-Running. The Team have toured their performances and teaching across five continents for clients including the British Council. Since 2006 the team has included co-creator of Parkour Malik Diouf. In 2009 the Team designed and opened the UK’s first permanent parkour site\, and have since launched two more. In 2013 they founded the international performance-parkour network to support the development of 2PK globally. They have appeared on BBC1’s Blue Peter and Sky1’s Got To Dance. <br />
Steam is a touring performance\, in which a group of urban explorers discover\, beneath canvas tarps\, the skeletal remains of a machine that changed the world. Inspired\, they shovel coal on the fires of the past. Engineers and drivers hurry to work at the sounds of a whistle’s blast\, and the passengers begin to dance. Inspired by classic movie genre Steam takes the UPG Team on a whistle stop tour through silent movies\, the Wild West\, James Bond\, WWI and the dark future of inner city commuting…<br />
Try out your own skills after the show - and you could even become part of the next performance!<br />
See also Weds June 1st.
URL;VALUE=URI:http://bathfringe.co.uk/single-event?u_name=Steam
SUMMARY:Steam
DTSTART:19700101T000000Z
END:VEVENT
END:VCALENDAR
内容生成如下:
$contents =
'BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTEND: '.dateToCal($dateend) .'
UID: '. uniqid() .'
DTSTAMP:'. dateToCal(time()) .'
LOCATION:'. escapeString($address) .'
DESCRIPTION:'. escapeString($description) .'
URL;VALUE=URI:'. escapeString($uri) .'
SUMMARY:'. escapeString($summary) .'
DTSTART:'.dateToCal($datestart) .'
END:VEVENT
END:VCALENDAR '
答案 0 :(得分:2)
我看到两个问题:
您的iCal文件在非法位置包含几个空格:
DTEND: 19700101T024640Z
^
UID: 5724dce4946da
^
END:VCALENDAR
^
嗯,从技术上讲,第二个可能不是无效的,因为UID
被定义为具有TEXT
值,但你应该准备好为此遇到麻烦。某些实现可能无法读取此内容,其他实现可能会剥离空间,其他实现可能包含它。
查看RFC 5545中的ABNF以获取正确的语法。通常,iCalendar中没有可选的空格。
DESCRIPTION
属性包含几个新的行序列,但未正确转义。内容行末尾的新行字符应转义为\n
(请参阅RFC 5545, Section 3.3.11)。所以DESCRIPTION属性应该是这样的(所有在一行中都有转义的新行字符):
DESCRIPTION:The Urban Playground Team are the original performance-parkour (2PK) company combining urban & contemporary dance with authentic French Free-Running. The Team have toured their performances and teaching across five continents for clients including the British Council. Since 2006 the team has included co-creator of Parkour Malik Diouf. In 2009 the Team designed and opened the UK’s first permanent parkour site\, and have since launched two more. In 2013 they founded the international performance-parkour network to support the development of 2PK globally. They have appeared on BBC1’s Blue Peter and Sky1’s Got To Dance. <br />\nSteam is a touring performance\, in which a group of urban explorers discover\, beneath canvas tarps\, the skeletal remains of a machine that changed the world. Inspired\, they shovel coal on the fires of the past. Engineers and drivers hurry to work at the sounds of a whistle’s blast\, and the passengers begin to dance. Inspired by classic movie genre Steam takes the UPG Team on a whistle stop tour through silent movies\, the Wild West\, James Bond\, WWI and the dark future of inner city commuting…<br />\nTry out your own skills after the show - and you could even become part of the next performance!<br />\nSee also Weds June 1st.
更好的是,像这样折叠线
DESCRIPTION:The Urban Playground Team are the original performance-park
our (2PK) company combining urban & contemporary dance with authentic
French Free-Running. The Team have toured their performances and teach
ing across five continents for clients including the British Council.
Since 2006 the team has included co-creator of Parkour Malik Diouf. In
2009 the Team designed and opened the UK’s first permanent parkour
site\, and have since launched two more. In 2013 they founded
the international performance-parkour network to support the development
of 2PK globally. They have appeared on BBC1’s Blue Peter and Sky1’s
Got To Dance. <br />\nSteam is a touring performance\, in which a group
of urban explorers discover\, beneath canvas tarps\, the skeletal
remains of a machine that changed the world. Inspired\, they shovel coal
on the fires of the past. Engineers and drivers hurry to work at the
sounds of a whistle’s blast\, and the passengers begin to dance.
Inspired by classic movie genre Steam takes the UPG Team on a whistle
stop tour through silent movies\, the Wild West\, James Bond\, WWI and
the dark future of inner city commuting…<br />\nTry out your own
skills after the show - and you could even become part of the next
performance!<br />\nSee also Weds June 1st.
注意每行开头的前导空格。折叠在Section 3.1 of RFC 5545中解释。
另请注意,iCalendar不支持HTML标记。客户可能会或可能不会按照您的意图解释这一点。有些客户只会在计划文字中显示<br />
个标签。但是,没有iCalendar验证器应该抱怨这一点。
关于标题,iCalendar的正确内容类型为text/calendar
,因此如果您通过HTTP返回此内容,则发送以下标题:
Content-type: text/calendar
如果您希望将其发布为日历应用程序可以订阅的日历,则应考虑向METHOD:PUBLISH
对象添加VCALENDAR
字段,如RFC 5546中所述。
最后:考虑使用现有的iCalendar库来处理所有这些(转义,折叠......)。看看Sabre-VObject。
答案 1 :(得分:0)
$ eol =“\ r \ n”;
$contents =
'BEGIN:VCALENDAR'.$eol.'
VERSION:2.0'.$eol.'
PRODID:-//hacksw/handcal//NONSGML v1.0//EN'.$eol.'
CALSCALE:GREGORIAN'.$eol.'
BEGIN:VEVENT'.$eol.'
DTEND: '.dateToCal($dateend) .$eol.'
UID: '. uniqid() .$eol.'
DTSTAMP:'. dateToCal(time()) .$eol.'
LOCATION:'. escapeString($address) .$eol.'
DESCRIPTION:'. escapeString($description) .$eol.'
URL;VALUE=URI:'. escapeString($uri) .$eol.'
SUMMARY:'. escapeString($summary) .$eol.'
DTSTART:'.dateToCal($datestart) .$eol.'
END:VEVENT'.$eol.'
END:VCALENDAR '.$eol;
主要的是你需要在每个链接中断后添加$ eol。