dounan4479 2018-07-03 12:25
浏览 38
已采纳

我正在尝试使用php file()并从另一个目录中提取并在文件名中使用*

I am trying to use the file () function to read a file into an array from another directory. The directory would be at ../data. Also need to read the file in as anything beginning with PaymentPlanExport*. I will be reading these in monthly and only one file will be in that directory at a time. The only difference between the file are the date.

$records = file("PaymentPlanExport*");
  • 写回答

1条回答 默认 最新

  • duanlou2917 2018-07-03 12:34
    关注

    file doesn't support wildcards. If you need wildcard support for file operations in php, you could use the glob function, which returns a array of all matching file.

    In your case, you could simply use file(glob('PaymentPlanExport*')[0]) - but I would recommend to add some checks, if the file really exists.

    $pattern = '../data/PaymentPlanExport*';
    $files = glob($pattern);
    if (count($files) != 1) {
        // error handling
    }
    $f = fopen($files[0]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大