2016-02-26 65 views

回答

0

使用此代碼。

$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 ;"; 
相關問題