Jump to content

Display file starting with letter


avo

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]
Link to comment
https://forums.phpfreaks.com/topic/22300-display-file-starting-with-letter/
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]
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

Archived

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

×
×
  • Create New...

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.