dongshi4589 2013-07-24 11:42
浏览 32
已采纳

PHP - 搜索并替换然后排序和回显

I've managed (well, stackoverflow has shown me how) to search a directory on my server and echo and image. The trouble is the images in the folder are named by an IP camera yy_mm_dd_hh_mm where dd (and other date digits) have either one or two digits. I need them to have a preceeding zero so that I don't end up with, for example, an image taken at 9:50am being treated as a higher value than the photo taken more recently, at 10:05am. (I want it to treat it as 09_50 and 10_05 to fix the issue).

I've looked at search and replace but cannot get this to work within my current code:

function webcam_image () {
foreach (glob( "../camera/IPC_IPCamera*.jpg") as $f ) {
$list[] = $f;
}
sort($list);
echo array_pop($list);   
}

example file = IPC_IPCamera_13_7_24_9_57_45.jpg

any help would be much appreciated!

Thanks

Ali

  • 写回答

4条回答 默认 最新

  • down100009 2013-07-24 11:56
    关注

    I would ignore the file name altogether and use a DirectoryIterator, fetching the files actual modified date. Something like this might work.

    $files = array();
    $iterator = new \DirectoryIterator('/path/to/dir');
    foreach ($iterator as $file) {
      if(! $file->isDot()) $files[$file->getMTime()] = $file->getFilename();
    }
    ksort($files);
    
    print_r($files);
    

    Take a look here for more information: http://php.net/manual/en/class.directoryiterator.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥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