...

View Full Version : Edit an array



GO ILLINI
03-05-2007, 04:15 AM
I have an array that is all the files in a directory.

<?php
$dir = "../images/galleries/";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
}
sort($files);
print_r($files);
?>
How would I
-Strip off the . and the .. at the begining
-Make it so that I can turn each one of them into a different link
I used to be great at this stuff, but its been awhile...

Thanks,
Adam

firepages
03-05-2007, 04:46 AM
I prefer glob...


<?php
$dir = "../images/galleries/";
$files = glob($dir.'*.*');
//sort($files);
foreach($files as $f){
echo '<a href="'.$f.'">'.basename($f).'</a><br />';
}
?>

GO ILLINI
03-05-2007, 05:40 AM
Thanks man works great. Also now I can have it return only folders or files.
I dont think ive ever used glob before... Ill go read up on it.

-Adam



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum