How can PHP be used to properly handle line breaks in VCalendar files to ensure compatibility with Outlook?

When creating VCalendar files in PHP, it is important to properly handle line breaks to ensure compatibility with Outlook. To do this, line breaks should be encoded as "\r\n" (carriage return + line feed) instead of just "\n". This ensures that Outlook can correctly interpret the line breaks and display the calendar events properly.

// Sample PHP code to properly handle line breaks in VCalendar files for Outlook compatibility
$vcalendar = "BEGIN:VCALENDAR\r\n";
$vcalendar .= "VERSION:2.0\r\n";
$vcalendar .= "PRODID:-//Your Company//Your App//EN\r\n";
$vcalendar .= "BEGIN:VEVENT\r\n";
$vcalendar .= "UID:1234567890\r\n";
$vcalendar .= "DTSTART:20220101T080000\r\n";
$vcalendar .= "DTEND:20220101T090000\r\n";
$vcalendar .= "SUMMARY:Sample Event\r\n";
$vcalendar .= "DESCRIPTION:This is a sample event description.\r\n";
$vcalendar .= "END:VEVENT\r\n";
$vcalendar .= "END:VCALENDAR\r\n";

// Output the VCalendar file
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="calendar.ics"');
echo $vcalendar;