iCal is a file format which allows the sharing of generic calendar information. A lot of sites such as HomeAway and AirBnB generate iCal files so you can synchronise bookings across platforms on which your properties may be advertised.

If one of these platforms is your own website, you may need to read the external files (from HomeAway etc) and enter the information into your database to keep it up to date. Reading and/or writing these files is actually pretty straightforward – you just need to know the correct format.

First of all, let’s take a look at what a basic iCal file looks like:

(A handy guide to the specification of each attribute is here http://www.kanzaki.com/docs/ical/)


To create this, simply loop through the data you wish to include (i.e. each of the bookings for your property) and build a string to iCal specification. Don’t forget to set the correct headers before you echo out the string; these tell the program reading your file that it is in iCal format.


A very useful function I found (thanks Steffen Behn http://stackoverflow.com/a/13844260) simplifies this immensely.

Use the above function as such:

Then you can do with the data as you wish. In the above example I’ve converted the dates to standard “Y-m-d” format and assigned the various data to variables. You would then most likely input this into your database in order to keep your calendar up to date with the source of the ics file.

And that’s it!


This code is free to use at your own discretion. It comes without warranty. Please feel free to feedback any edits.

Add a comment



So Helpful!!!
Thank you very much

Add a comment