snowman2344 Posted September 15, 2010 Share Posted September 15, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/213507-add-text-file-to-mysql-db/ Share on other sites More sharing options...
DavidAM Posted September 15, 2010 Share Posted September 15, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213507-add-text-file-to-mysql-db/#findComment-1111474 Share on other sites More sharing options...
snowman2344 Posted September 18, 2010 Author Share Posted September 18, 2010 thanks that put me on track Quote Link to comment https://forums.phpfreaks.com/topic/213507-add-text-file-to-mysql-db/#findComment-1112343 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.