如何在codeingiter中获取包含子字符串的所有文件,如“abc”

时间:2017-10-12 08:13:59

标签: php codeigniter

我有很多文件名,例如“black_abc”,“white_abc”,“black_cde”,“white_abc”。如何只获取文件名包含“abc”的文件?

2 个答案:

答案 0 :(得分:0)

您可以使用strpos()吗?

http://php.net/manual/en/function.strpos.php

<?php
 $arr = ["black_abc","white_abc","black_cde","white_abc"];
 foreach($arr as $i => $item) {
   if (strpos($item, '_abc')) {
     echo 'found _abc in ' . $item;
     echo '<br>';
   }
 }
?>

输出:

found _abc in black_abc
found _abc in white_abc
found _abc in white_abc

答案 1 :(得分:0)

使用glob()功能,如下所示:

<?php
$filename = "absolute path of the directory/*abc*";
foreach (glob($filename) as $filefound) {
    echo "$filefound size " . filesize($filefound) . "\n";
}
?>