map200uk Posted April 18, 2007 Share Posted April 18, 2007 Hi, sorry to post this, but i cannot work out my problem with my code i am trying to write the results to an array each time a match is found <?php $mp3[]=array(); $x=0; function scandir1($dir) { echo "the value of x is $x"; $dirlist = opendir($dir); // open the directory while ($file = readdir ($dirlist)) // while file = readdir { if ($file != '.' && $file != '..') //if file = . current dir or .. back 2 dirs { $newpath = $dir.'/'.$file; $level = explode('/',$newpath); //split newpath into array so /home/mark becomes array[0]=>home array[1=>mark if (is_dir($newpath)) { echo "\nDirectory found at \n + $newpath"; $content=scandir1($newpath); }else{ //if newpath is not dir echo "\nno dir"; $filen=end($level); if(ereg("mp3$",$filen)) { $x=$x+1; echo "The value of x is $x"; echo "we found mp3, $filen @ $newpath"; $mp3[]=$filen; } echo "**** $filen" ; } } } closedir($dirlist); echo "\nCHECK"; return $mp3; } echo '<pre>'; print_r(scandir1('.')); echo '</pre>'; ?> all i want to do is if a file ending mp3 is found add the file to the mp3 array however each time the array only contains 1 entry if(ereg("mp3$",$filen)) { $x=$x+1; echo "The value of x is $x"; echo "we found mp3, $filen @ $newpath"; $mp3[]=$filen; } thanks Link to comment https://forums.phpfreaks.com/topic/47635-help-with-some-code-cant-work-it-out/ Share on other sites More sharing options...
map200uk Posted April 18, 2007 Author Share Posted April 18, 2007 im sure its something stupid im messing, i just cant seem to work it out;/ Link to comment https://forums.phpfreaks.com/topic/47635-help-with-some-code-cant-work-it-out/#findComment-232621 Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 http://us.php.net/manual/en/function.pathinfo.php Makes it alot easier to check the extension. Link to comment https://forums.phpfreaks.com/topic/47635-help-with-some-code-cant-work-it-out/#findComment-232640 Share on other sites More sharing options...
map200uk Posted April 18, 2007 Author Share Posted April 18, 2007 thanks mate! mark Link to comment https://forums.phpfreaks.com/topic/47635-help-with-some-code-cant-work-it-out/#findComment-232663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.