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://tools.ietf.org/html/rfc2445#section-4.1
This validator tells me is outdated but when I change to , it invalidates my DESCRIPTION. - http://severinghaus.org/projects/icv/
I've tried
I've tried $description = str_replace(" ", ' ', $htmlMsg); $description = str_replace("
",' ',$description); $description = (str_replace(";","\;",str_replace(",",'\,',$description)));
in combination with
I've tried
$htmlMsg = "Adding event to your schedule does not confirm your reservation.
Visit http://www.website.com for attendance details."
$temp = str_replace(array("
"),"
",$htmlMsg);
$lines = explode("
",$temp);
$new_lines =array();
foreach($lines as $i => $line)
{
if(!empty($line))
$new_lines[]=trim($line);
}
$desc = implode("
",$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
";
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
";
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@gmail.com
DTSTAMP:20180208T150517Z
SUMMARY:Committee Meeting
UID:200893236
DTSTART:20180208T170000Z
DTEND:20180208T180000Z
DESCRIPTION:Adding event to your schedule does not confirm your reservation.
Visit http://www.website.com for attendance details.
X-ALT-DESC;FMTTYPE=text/html:Adding event to your schedule does not confirm your reservation.
Visit 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.
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/
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.