Jump to content

[SOLVED] Reading Tab Delimited Files


winmastergames

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.