Jump to content

Archived

This topic is now archived and is closed to further replies.

avo

Display file starting with letter

Recommended Posts

Hi All

ive been playing with directory functions
ok i can open the files in a directory and view them but how would i only view the ones starting with a or A

my code is [code]
<?
//Open directory
$dir = opendir("./directory name");
//List files in images directory
while (($file = readdir($dir)) !== false)
  {
  echo "filename: " . $files . "<br />";
  }
  closedir($dir);
?>
[/code]

Share this post


Link to post
Share on other sites
add this if statement

[code]<?
//Open directory
$dir = opendir("./directory name");
//List files in images directory
while (($file = readdir($dir)) !== false)
  {
if(ereg ("^[Aa].*", $file))
    echo "filename: " . $files . "<br />";
  }
  closedir($dir);
?>[/code]

Share this post


Link to post
Share on other sites
Hi Thank you

been think about that for ages

i was trying at first to do strpos()

but this works great this is what i ended up with

[code]

<?
//Open directory
$dir = opendir("./coupon");
//List files in images directory
while (($file = readdir($dir)) !== false)
  {
if (ereg ("^[Aa].*", $file)){
$replace=str_replace(".php","",$file);
echo "<a href='coupon/$file'> " . $replace . "</a><br />";
  }
}
  closedir($dir);
 
?>

[/code]

Thanks Appriciated

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.