dtbhp60824 2018-06-29 05:10
浏览 76

在1个php文件中处理多个CSV文件

I have a php file in which i am extracting the data from a csv file and making an array and including it to another php which has its html/css to display the retrieved data. Now I have multiple such csv files for which the same task needs to be done.I am currently doing it by manually copying the whole php file into a new php file and changing the file name to be extracted and the array names. Is there a better way of achieving this task?

  • 写回答

2条回答 默认 最新

  • duanbo19834 2018-06-29 06:20
    关注

    Define a class (e.g. Reader) and move the file content extract logic to a method of that class (e.g. getFileContents) and make a call to that class to read file data as below:

    $reader = new Reader();
    $data = $reader->getFileContents(filename);
    

    So you can repeat the method call logic as many times as you want from as many files as you want as long as your class is accessible from the caller file.

    Hope this helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog