What potential pitfalls should developers be aware of when manually building iCalendar files in PHP?

One potential pitfall when manually building iCalendar files in PHP is not properly escaping special characters, which can lead to syntax errors or corrupted data in the resulting file. To avoid this issue, developers should use PHP's built-in `htmlspecialchars()` function to escape special characters before adding them to the iCalendar file.

// Example of properly escaping special characters in an iCalendar file
$event_description = "This is a description with special characters like & and <";
$escaped_description = htmlspecialchars($event_description);

$ical_content = "BEGIN:VEVENT\n";
$ical_content .= "DESCRIPTION:" . $escaped_description . "\n";
$ical_content .= "END:VEVENT\n";

// Output the iCalendar content
echo $ical_content;