简体   繁体   中英

Sending certain Lines and Characters to MySql using PHP from a Text File

long time looker, first time poster. Need some help with a little project I am working on, and some suggestions.

I have a file, call it testdex.dex. It's a text file, containing a output which is delimited by "** this is a snippet of the file. It's static, the fields never change.

I am trying to use PHP to parse the file, and forward the numbers to the appropriate Database, and tables I have already set up. I am not very proficient at PHP and was hoping for a little help...

PA1 represents the following: for instance: 11 is the selection, 125 is the price, $1.25.

PA2 represents the following: 159 sales $365.00 cost Each selection has a PA1, and PA2. There is a lot of other junk in the file that is not needed. I am trying to extract the Selection, Price, Sales, and cost from the file. I have tried breaking the file down into arrays using * as the delimeter with no luck.

Any pointers/ ideas will be greatly appreciated!!!

CA1*MEI50884419 *000000000000*0000**
BA1*MEI11700033 *VN200R     *0000**
CA3*0*0*0*0*1250210*193480*227330*8294
CA4*0*0*223470*2060
CA9*0*0
CA17*0*5*76*2*6
CA17*1*10*117*0*38
CA17*2*25*167*28*66
CA17*4*100*30*0*0
DA2*0*0*0*0
TA2*0*0*0*0
LS*0100
PA1*11*125*
PA2*214*36500*0*0*0*0
PA1*12*125*
PA2*159*24700*0*0*0*0
PA1*13*125*
PA2*250*31650*0*0*0*0
PA1*14*125*
PA2*205*26450*0*0*0*0
PA1*15*125*
PA2*178*23775*0*0*0*0
PA1*16*125*
PA2*159*20025*0*0*0*0
PA1*17*125*

This is a very simplified example but may point you in the right direction.

$fp = fopen("/home/user/directory/estdex.dex","r");
while (($text= fgets($fp , 4096)) !== false) {
  $data = explode('*'$text);
  $sql="INSERT INTO `table` (`col1`, `col2`) VALUES ('$data[0]', '$data[1]')";
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM