VCALENDAR file with newlines in DESCRIPTION field

Hopefully if anyone else has this problem, they’ll find this post. If you’re attempting to output some data in a MySQL database as a VCALENDAR file that is viewable in Apple Calendar or Outlook or whatever, an incorrect newline character in any field can make that event not show up (or make the entire file invalid in some applications).

What you’re looking for is an escaped newline character. Newlines are stored in MySQL as \n. You want to escape that character in your ics file, so replace \n with \\n. While you’re at it, it’s a good idea to replace ; with \; and , with \,. There may also be others, but those are the ones I’ve found so far.

About Scott Allen

Scott Allen is a web developer from Indianapolis, Indiana. He has been working with HTML, CSS, PHP, & MySQL since the late '90s, and has extensive experience in database design and development, server-side scripting, content management, and front-end user experience, especially in the creation of educational content. Connect with Scott on Twitter (preferably), or Facebook or Google+ (if you aren't in a hurry).
This entry was posted in Code, Tech and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *