drhzn3911 2016-06-10 09:55
浏览 58
已采纳

上传CSV或XML以进行编辑和返回

I haven't done much coding in the way of HTML5 and PHP before as ive always used Python and only created in system applications instead of web based apps.

Ive tried to find but could not, any information that might assist me with my latest task.

I would like for users to be able to upload a CSV or XML file (Havent decided on format yet) that contains SKUs in one field and Prices in another (Columns).

I then want the user to be able to specify a set of variables and have the document edited to that effect.

Im not sure if I would have to use MySQL to achieve this, and I have no experience with it so if I can at all avoid it then that would be preferable.

Any advice / suggestions on material for doing this, or even actual examples of how this might be achieved would go a long way to increasing my understanding of how to approach this task.

Kind Regards. Lewis

  • 写回答

1条回答 默认 最新

  • duankuang1046 2016-06-10 10:40
    关注

    You can use fgetcsv method and fputcsv methods to manipulate a csv file in php. For xml files you can use simpleXML parser

    I will give an example for CSV files in php.

    Reading a CSV file

    if(file_exists("/tmp/my_file.csv")){
        $filex = fopen("/tmp/my_file.csv","r");
    }
    else{
        echo "file not found";
    }
    $data = array();
    while(!feof($file))
    {
      $data[] = fgetcsv($file);
    }
    fclose($filex);
    //now you can manipulate $data as you wish
    

    Writing to CSV file

    $list = array
    (
    "abcd,efgh,ijkl,mnop",
    "qrst,uvwx,yzab,cdef"
    );
    
    $file = fopen("my_file.csv","w");
    
    foreach ($list as $line)
      {
      fputcsv($file,explode(',',$line));
      }
    
    fclose($file);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用