a problem looping

a problem looping

Posted by: memco
Posted on: 2006-12-14 13:36:00

$getID3 = new getID3;
$dir = 'sermons';
$result = scandir ($dir);
foreach ($result as $file) {
echo 'scanning
';
print "$file";
$fileinfo = $getID3->analyze($file);
$title = $fileinfo['id3v2']['comments']['title'][0];
echo ($title);
}

I seem to be hitting a problem in this code wherein the foreach loop does not iterate through every element of $result. It stops after the first file, which is ".". All I'm really after is the $title variable for all files in a directory, but I'm having problems isolating those.

Re: a problem looping

Posted by: silkrooster
Posted on: 2006-12-14 19:40:00

Try this:
$dir = './sermons';
$d=opendir($dir);
while (false !== ($results = readdir($d))) {
$result[]=$results;
}
foreach ($result as $title) {
if (preg_match('/(comments|title)$/', $title)) {
echo "$titlen";
}
Hopefully this works, been awhile. what this should do is take each directory listing and put it in an array, then it will search for a directory name of comment or title and print that directory name.
Silk

My website

Re: a problem looping

Posted by: memco
Posted on: 2006-12-14 21:10:00

Got it working. Thanks

Re: a problem looping

Posted by: silkrooster
Posted on: 2006-12-15 00:41:00

Glad you got it working, I was a little worried that I typed something wrong. lol.
Silk

My website

Tags: foreach