Jump to content

Add text file to mysql DB


snowman2344

Recommended Posts

I am trying to add a txt file to a mysql database. Is there any one that can help?

Here are the details

 

TEST.TXT

contains the following

 

A00120091001999999990000020000000000000000000000000000000000000000000000000

A00220091001999999990000061000000000000000000000000000000000000000000000000

A00320091001999999990000068750000000000000000000000000000000000000000000000

A00420091001999999990000033500000000000000000000000000000000000000000000000

A00520091001999999990000062650000000000000000000000000000000000000000000000

A00620070401999999990000042350000000000000000000000000000000000000000000000

A00720091001999999990000032350000000000000000000000000000000000000000000000

A00820070401999999990000010250000000000000000000000000000000000000000000000

And so on up to 200 rows long

 

I need to split each row the same way and add them to a table

I will use the first row as an example

Character 1 to 4 (A001) entered into a field called name

Character 5 to 12 (20091001) entered into a field called efdate

Character 13 to 20 (99999999) entered into a field called exdate

Character 21 to 31 (00000200000) entered into a field called prfee

Character 32 to 42 (00000000000) entered into a field called assfee

Character 43 to 53(00000000000) entered into a field called spfee

Character 54 to 64 (00000000000) entered into a field called anfee

Character 65 to 75 (00000000000) entered into a field called nanfee

 

Thanks in advance for the help

 

Link to comment
https://forums.phpfreaks.com/topic/213507-add-text-file-to-mysql-db/
Share on other sites

Something like this(not tested):

$fs = fopen('TESTS.TXT', 'r');
while ($line = fgets($fs)) {
  $name = substr($line, 0, 4);
  $efdate = substr($line, 4, ;
  $exdate = substr($line, 12, ; 
// ... MORE LINES LIKE THAT
// NOTE: for substr() the the first character of the string is at position 0 (zero)

// DO SOMETHING WITH THE DATA
}
fclose($fs);

 

There are other ways to do this; like file() which will load the entire file into an array of lines.

 

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.