winmastergames Posted June 7, 2008 Share Posted June 7, 2008 Well Ive got this code: <?php mysql_connect("localhost", "root", "pass"); mysql_select_db("webmeterreadgrid"); # first get a mysql connection as per the FAQ $fcontents = file ('./206011569-6.ls2'); # expects the csv file to be in the same dir as this script for($i=0; $i<sizeof($fcontents); $i++) { $line = trim($fcontents[$i]); $arr = explode("\t", $line); #if your data is comma separated # instead of tab separated, # change the '\t' above to ',' $sql = "insert into coredatatest values ('". implode("','", $arr) ."')"; mysql_query($sql); echo $sql ."<br>\n"; if(mysql_error()) { echo mysql_error() ."<br>\n"; } } ?> And Is there any way to make this code Start from a certain line like line: 7 so it starts the process on the file on line 7 so it doesnt read any data on line 1,2,3,4,5,6 Thanks Link to comment https://forums.phpfreaks.com/topic/109099-solved-reading-tab-delimited-files/ Share on other sites More sharing options...
sasa Posted June 7, 2008 Share Posted June 7, 2008 change to # expects the csv file to be in the same dir as this script $skip_first_n_lines = 6; for($i=$skip_first_n_lines; $i<sizeof($fcontents); $i++) { etc. Link to comment https://forums.phpfreaks.com/topic/109099-solved-reading-tab-delimited-files/#findComment-559675 Share on other sites More sharing options...
winmastergames Posted June 7, 2008 Author Share Posted June 7, 2008 Thanks Alot Link to comment https://forums.phpfreaks.com/topic/109099-solved-reading-tab-delimited-files/#findComment-559678 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.