doucheng7234 2015-01-20 20:41
浏览 13
已采纳

使用PHP从文本文件向MySql发送某些行和字符

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*
  • 写回答

1条回答 默认 最新

  • doushajian2018 2015-01-20 20:54
    关注

    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]')";
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 三分类机器学习模型可视化分析
  • ¥15 本地测试网站127.0.0.1 已拒绝连接,如何解决?(标签-ubuntu)
  • ¥50 Qt在release捕获异常并跟踪堆栈(有Demo,跑一下环境再回答)
  • ¥30 python,LLM 文本提炼
  • ¥15 关于将inet引入的相关问题
  • ¥15 关于一个倒计时的操作和显示设计
  • ¥15 提问STK的问题,哪位航天领域的同学会啊
  • ¥15 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
  • ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
  • ¥15 关于#java#的问题,请各位专家解答!