Jump to content


Photo

Display file starting with letter


  • Please log in to reply
2 replies to this topic

#1 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 27 September 2006 - 09:54 PM

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
<?
//Open directory
$dir = opendir("./directory name");
//List files in images directory
while (($file = readdir($dir)) !== false)
  {
  echo "filename: " . $files . "<br />";
  }
  closedir($dir);
?>

Im loving it ........

#2 fooDigi

fooDigi
  • Members
  • PipPipPip
  • Advanced Member
  • 250 posts
  • LocationDuluth, Mn

Posted 27 September 2006 - 10:05 PM

add this if statement

<?
//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);
?>

All your base are belong to us.

#3 avo

avo
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts
  • Locationstaffordshire uk

Posted 27 September 2006 - 10:35 PM

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


<?
//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);
  
?>


Thanks Appriciated
Im loving it ........




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users