简体   繁体   中英

How to import ics file into mysql using php?

I want to import data from an ics file published using MS-outlook into mysql. How to do this?

use this code.

$filename = "test.tsv";
//Read the file
$content = file_get_contents($filename);
//Split file into lines
$lines  = explode("\n", $content);

//Find columns by reading first line
$columns = explode("\t", $lines[0]);

//Construct create table
$sql_table = "CREATE TABLE IF NOT EXISTS `tsv` (\n";
//Set first column ID
$sql_table .= "  `id` int(11) NOT NULL AUTO_INCREMENT,\n";
foreach ($columns as $column) {
    //Add each column to the string as type text
    $sql_table .= "  `".addslashes($column)."` text NOT NULL,\n";
}
$sql_table .= "  PRIMARY KEY (`id`)\n) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM