Вы можете сделать что-то подобное:
$string = '01467_rbt.csv, 0152t.csv, 35302.png';
$array = explode(", ", $string); // get an array with each filename
$result = array();
foreach ($array as $value) {
$dexplode = explode(".", $value); // explode the filename on .
$extension = end($dexplode); // get the last --> extension
if(isset($result[$extension])) // if it's an existing extension
$result[$extension]++; // add 1
else // if not existing
$result[$extension]=1; // init to 1
}
var_dump($result);
И, например, чтобы иметь количество CSV файла:
$result["csv"];
Это результат var_dump():
array (size=2)
'csv' => int 2
'png' => int 1
Редактировать:
У вас есть много возможностей найти расширение файла:
$filename = 'mypic.gif';
// 1. The "explode/end" approach
$ext = end(explode('.', $filename));
// 2. The "strrchr" approach
$ext = substr(strrchr($filename, '.'), 1);
// 3. The "strrpos" approach
$ext = substr($filename, strrpos($filename, '.') + 1);
// 4. The "preg_replace" approach
$ext = preg_replace('/^.*\.([^.]+)$/D', '$1', $filename);
// 5. The "never use this" approach
// From: http://php.about.com/od/finishedphp1/qt/file_ext_PHP.htm
$exts = split("[/\\.]", $filename);
$n = count($exts)-1;
$ext = $exts[$n];
Подробнее here
Большое спасибо, вы очень помогли мне! –