Page 1 of 1

Array questions

Posted: Fri Jul 28, 2006 11:34 am
by toasty2
I have two problems with my php script that lists files in a directory, it shows blank filesnames for some of the listing (why?). And, with the webbrowser I use to display the directory list, it cant show all of the listing (no scrolling is allowed in this program) so I need to split the array into 3 parts so I can have 3 columns, each column in a different array and I need to remove the empty filenames from the array. So far I have:

Code: Select all

<?
$path = "/homepages/21/d155481990/htdocs/server";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) 
{
   if($file!="." && $file!=".." && $file!="")
$newfile = str_replace(".mp3", "", $file);
      echo "$newfile<br/>";
}
closedir($dir_handle);
?>
And yes, it removes .mp3 from the name before displaying it, This is for a special program.

How can I split $newfile into 3 arrays?

Posted: Fri Jul 28, 2006 12:42 pm
by pickle
You should look at glob(). It's much easier & nicer to get all the files from a directory.

As for splitting up your array into 3 arrays, look at array_slice()

Posted: Fri Jul 28, 2006 1:39 pm
by feyd
array_chunk() may be better suited for the splitting.. alternately, some clever math with a linear array works well too. Useful Posts has links -- the first two -- to possible mappings to help you output the data, depending on what direction and complexity you're going for.