1--TEST-- 2SPL: DirectoryIterator::getExtension() basic test 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip.. only for Unix'); 7} 8?> 9--FILE-- 10<?php 11$dir = __DIR__ . DIRECTORY_SEPARATOR . md5('DirectoryIterator::getExtension') . DIRECTORY_SEPARATOR; 12mkdir($dir); 13 14$files = array('test.txt', 'test.extension', 'test..', 'test.', 'test'); 15foreach ($files as $file) { 16 touch($dir . $file); 17} 18 19$dit_exts = array(); 20$nfo_exts = array(); 21$skip = array('.', '..'); 22 23foreach (new DirectoryIterator($dir) as $file) { 24 if (in_array($file->getFilename(), $skip)) { 25 continue; 26 } 27 $dit_exts[] = $file->getExtension(); 28 $nfo_exts[] = pathinfo($file->getFilename(), PATHINFO_EXTENSION); 29} 30var_dump($dit_exts === $nfo_exts); 31sort($dit_exts); 32var_dump($dit_exts); 33?> 34--CLEAN-- 35<?php 36$dir = __DIR__ . DIRECTORY_SEPARATOR . md5('DirectoryIterator::getExtension') . DIRECTORY_SEPARATOR; 37$files = array('test.txt', 'test.extension', 'test..', 'test.', 'test'); 38foreach ($files as $file) { 39 unlink($dir . $file); 40} 41rmdir($dir); 42?> 43--EXPECTF-- 44bool(true) 45array(5) { 46 [0]=> 47 string(0) "" 48 [1]=> 49 string(0) "" 50 [2]=> 51 string(0) "" 52 [3]=> 53 string(9) "extension" 54 [4]=> 55 string(3) "txt" 56} 57