doy57007 2013-05-25 02:50
浏览 225
已采纳

如何读取服务器上的所有现有CSV文件?

This question is a little complicated, but I will try my best to explain. Feel free to ask for clarification if my question does not make sense.

Situation:

On my server there will be a new CSV file added every day into a particular folder. The CSV files will all be kept in the same folder. They will have a name consistant with the day. For example log_2013_05_24.csv.

Objective:

I need to write a PHP program that will find all existing CSV files so that I can search through them. In the end I need to find all the dates that exist.

The data inside the CSV files looks similar to this:

4/14/13, 17:30:56, data, data, data, data
4/14/13, 17:31:06, data, data, data, data 
( ... about 10,000 of these ^ a new line for every 10 seconds all day )

I am using php explode to get the dates from my current CSV file. This will produce an array of strings similar to: '4/14/13'.

But there are two problems:

1: They are strings, not dates

2: I don't know how to find all existing CSV files so that PHP can search them.

  • 写回答

3条回答 默认 最新

  • duanche8554 2013-05-25 03:00
    关注

    Use DateTime class to create dates

    $str = '04/14/13';
    $date = new DateTime($str);
    echo $date->format('Y-m-d');
    

    Use glob() function to traverse filesystem

    $files = glob('*.csv');
    var_dump(files);
    

    Sample output:

    array(3) {
      [0]=>
      string(8) "test.csv"
      [1]=>
      string(9) "test1.csv"
      [2]=>
      string(9) "test2.csv"
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效