0

okay, been going round in circles with this, trying to get content on a new line or fold. I've tried two validators and can get this valid but it gives me line length warnings - https://icalendar.org/validator.html

I have no clue how to enter a CRLF as described in spec - https://www.rfc-editor.org/rfc/rfc2445#section-4.1

This validator tells me \n is outdated but when I change to \r\n, it invalidates my DESCRIPTION. - http://severinghaus.org/projects/icv/

I've also tried to escape using "\n" instead of "\n"

I've tried DESCRIPTION;ALTREP=" . $url . ":". $description ."

I've tried $description = str_replace("\r\n", '\n', $htmlMsg); $description = str_replace("
",'\n',$description); $description = (str_replace(";",";",str_replace(",",',',$description)));

in combination with DESCRIPTION:" . $description . "

I've tried

$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 currently:

    $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 protected]
    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";

In addition to the new line issue, I'd like to put a link in the description. Hoping a solution will be valid and function in Apple Calendar, Google and Outlook.

ics output

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 protected]
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

Appreciate any guidance! Many forums are 5-8 years old on this topic so hoping for something current.

2 Answers 2

5

1) for the CR LF, use:

echo chr(13).chr(10);

2) to 'fold' the lines I use something like this:

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) Links in the description. The spec does not allow/address html in the description. some applications may cope with it, many may not. Best bet is to put the raw url and hope the receiving application will turn it into a link. There is more info on that here: https://icalevents.com/4019-ics-feed-generation-with-html/

0
0

Remember you need to include the entire line in your line length calculation, which will also include the text "DESCRIPTION:". It's probably a good idea to create the line completely first and have a general routine to do the folding like anmari's code. I've received a few emails recently of users reporting a suspected line length calculation bug in my validator (iCalendar.org/validator.html) but they were not including "DESCRIPTION" in their line length calculation.

"DESCRIPTION" is only for text (welcome to the 1990's!). You are correct in using "X-ALT-DESC" in your example, which is the HTML version of the description text and has become the defacto standard for HTML in the description. You should include both since "DESCRIPTION" is the standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.