ics内容行验证和描述中的html

时间:2018-02-08 23:34:46

标签: php icalendar

好吧,一直围着这个圈子,试图在新线上获得内容或弃牌。我已经尝试了两个验证器并且可以使其有效,但它会给我一些行长警告 - https://icalendar.org/validator.html

我不知道如何按照规范https://tools.ietf.org/html/rfc2445#section-4.1

中的描述输入CRLF

这个验证器告诉我\ n已经过时但是当我更改为\ r \ n时,它会使我的描述无效。 - http://severinghaus.org/projects/icv/

我也试图逃避使用" \ n"而不是" \ n"

我已经尝试了

描述; ALTREP =" 。 $ url。 ":&#34 ;. $ description。"

我已经尝试过了     $ description = str_replace(" \ r \ n",' \ n',$ htmlMsg);     $ description = str_replace("
",' \ n',$ description);     $ description =(str_replace(";"," \;",str_replace(",",' \,', $描述)));

结合使用

描述:" 。 $ description。 "

我已经尝试了

$htmlMsg = "Adding event to your schedule does not confirm your reservation.\nVisit http://www.website.com for attendance details."
    $temp = str_replace(array("\r\n"),"\n",$htmlMsg);
    $lines = explode("\n",$temp);
    $new_lines =array();
    foreach($lines as $i => $line)
    {
        if(!empty($line))
        $new_lines[]=trim($line);
    }
    $desc = implode("\r\n ",$new_lines);
目前

php:

    $output = "BEGIN:VCALENDAR
    METHOD:PUBLISH
    VERSION:2.0
    PRODID:-//App, Inc.//Calendar//EN
    X-WR-TIMEZONE:America/Los_Angeles
    CALSCALE:GREGORIAN\r\n";
    foreach ($events as $event):
    $numb = $numb+1;$output .=
    "BEGIN:VEVENT
    ORGANIZER;CN=BB:MAILTO:email@gmail.com
    DTSTAMP:" . date(dateToCal) . "
    SUMMARY:" . $event['te']['title'] . "
    UID:" . $numb . $event['te']['id'] . "
    DTSTART:" . gmdate(DATE_ICAL, strtotime($event['te']['sdate'])) . "
    DTEND:" . gmdate(DATE_ICAL, strtotime($event['te']['edate'])) . "
    DESCRIPTION:" . $desc . "
    X-ALT-DESC;FMTTYPE=text/html:" . $desc . "
    LOCATION:" . $event['te']['location'] . " 
    END:VEVENT\r\n";
    endforeach;
    // close calendar
    $output .= "END:VCALENDAR";

除了新行问题,我还想在说明中添加一个链接。 希望解决方案在Apple Calendar,Google和Outlook中有效并正常运行。

ics输出

BEGIN:VCALENDAR
METHOD:PUBLISH
VERSION:2.0
PRODID:-//App, Inc.//Calendar//EN
X-WR-TIMEZONE:America/Los_Angeles
CALSCALE:GREGORIAN
BEGIN:VEVENT
ORGANIZER;CN=BB:MAILTO:email@gmail.com
DTSTAMP:20180208T150517Z
SUMMARY:Committee Meeting
UID:200893236
DTSTART:20180208T170000Z
DTEND:20180208T180000Z
DESCRIPTION:Adding event to your schedule does not confirm your reservation.\nVisit http://www.website.com for attendance details.
X-ALT-DESC;FMTTYPE=text/html:Adding event to your schedule does not confirm your reservation.\nVisit http://www.website.com for attendance details.
LOCATION:Conference Room 
END:VEVENT
END:VCALENDAR

感谢任何指导!很多论坛都是关于这个主题的5-8岁,所以希望能有一些最新的东西。

2 个答案:

答案 0 :(得分:1)

1)对于CR LF,请使用:

echo chr(13).chr(10);

2)折叠'我使用的东西是这样的:

function ical_split($value) {
/* "fold" any long content lines  See: http://www.ietf.org/rfc/rfc2445.txt, section 4.1 */

  $value = trim($value);
  $lines = array();
  while (strlen($value)>(75)) {
    $line = mb_substr($value, 0, 75);
    $llength = mb_strlen($line);  //  must use mb_strlen with mb_substr otherwise will not work things like  
    $lines[] = $line.chr(13).chr(10).chr(32); /* CRLF and space*/
    $value = mb_substr($value, $llength); /* set value to what's left of the string */
  }

  if (!empty($value)) {
    $lines[] = $value; /* the last line does not need a white space */
  }
  return (implode($lines));
}

3)描述中的链接。该规范不允许/解释说明中的html。一些应用程序可能会应对它,许多可能不会。最好的办法是放置原始网址,并希望接收应用程序将其转换为链接。这里有更多信息:https://icalevents.com/4019-ics-feed-generation-with-html/

答案 1 :(得分:0)

请记住,您需要在行长计算中包含整行,其中还包括文字“DESCRIPTION:”。首先完全创建该行并且有一个像anmari代码那样进行折叠的通用例程可能是个好主意。我最近收到了一些用户在我的验证器(iCalendar.org/validator.html)中报告可疑行长计算错误的电子邮件,但他们的行长计算中没有包含“DESCRIPTION”。

“DESCRIPTION”仅适用于文字(欢迎来到1990年代!)。您在示例中使用“X-ALT-DESC”是正确的,这是描述文本的HTML版本,并且已成为描述中HTML的事实标准。您应该包括两者,因为“DESCRIPTION”是标准。

相关问题