fastread homefastrread library fastread menu

PHP Tutorial : Import events from .ICS file to MySQL table using PHP

Tutorial by:Admin      Date: 2018-10-26 05:12:54

❰ Previous Next ❱

As we know, the .ics file format is the universal calendar format that is used to store the calendar file in a text file. Let's create a PHP function that will import data from .ics file and store in MySQL database.

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

import from ics

PHP Code

$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, ',');




connection.php file

host="localhost";// Your Host name
$uname="******"; // Your Database  User name
$pass="*******"; // Your Database password 
$database = "********"; // Your Database name

or die("Database Connection Failed");
$selectdb=mysql_select_db($database) or die("Database could not be selected"); 
or die("database cannot be selected 

❰ Previous Next ❱

PHP Tutorial

Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website