As we know .ICS file format is universal calendar format used to store calendar information within a text file. Lets create a PHP function which will import data from .ICS file and store in MySQL database.

Here we have included a php class file called icalendar.php having class called iCalendar, which will read the ICS file and convert the data to Array format. Once you get the data array you can either save it or you can show it in your webpage in tabular format.

import from ics

PHP Code

$records = mysql_num_rows(mysql_query("select * from events"));
if ($_POST['stage'] == 1) {
$ical = new iCalendar();
$filename = $_FILES['file1']['tmp_name'];
$ical_data = $ical->get_all_data();

$timezone = "{$ical_data['VCALENDAR']['X-WR-TIMEZONE']}";
if (function_exists('date_default_timezone_set'))
$strsql1 = "Insert into events (ID,StartDate,StartTime,EndDate,EndTime,Title,
Location,Description) values ";
if (!empty($ical_data['VEVENT'])) {
foreach ($ical_data['VEVENT'] as $key => $data) {

//get StartDate And StartTime
$start_dttimearr = explode('T', $data['DTSTART']);
$StartDate = $start_dttimearr[0];
$startTime = $start_dttimearr[1];

//get EndDate And EndTime
$end_dttimearr = explode('T', $data['DTEND']);
$EndDate = $end_dttimearr[0];
$EndTime = $end_dttimearr[1];

$strsql1 = rtrim($strsql1, ',');




Download File

Total Downloads: 1893