php handle opendir while false file readdir handle if preg_match txt f

1
2
3
4
5
6
<?php
$handle = opendir('.');
while (false !== ($file = readdir($handle)))
if(preg_match('/\.txt$/', $file))
echo reset(explode('.', $file)) . "\n";
closedir($handle);