BrandonE97 Posted February 25, 2007 Share Posted February 25, 2007 Im trying to split up a list of filenames in a for loop. When the loop runs I have the code: <?php list($fname,$fext)=split('.',$dirArray['$index']); ?> but Im unable to use the $fname or $fext variables after that. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 25, 2007 Share Posted February 25, 2007 $string = "hello.how"; list($hi,$h) = explode('.',$string); echo $hi;//output = hello I would use explode instead of split. Quote Link to comment Share on other sites More sharing options...
BrandonE97 Posted February 25, 2007 Author Share Posted February 25, 2007 Now I have list($fname,$fext)=explode('.',$dirArray['$index']); but it still dont work. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 25, 2007 Share Posted February 25, 2007 What is in $dirArray['$index']? Quote Link to comment Share on other sites More sharing options...
BrandonE97 Posted February 25, 2007 Author Share Posted February 25, 2007 A directory listing of file.mp3 and file.pdf and other file.whatevers. About 300 files in the directory. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 25, 2007 Share Posted February 25, 2007 if its a file name, then this absolutely 100% work: list($the_file_bit, $extension) = explode('.', $dirArray['$index']); if it doesnt then its a problem with $dirArray['$index'] not being set correctly, or not having the correct data. Quote Link to comment Share on other sites More sharing options...
BrandonE97 Posted February 25, 2007 Author Share Posted February 25, 2007 Im able to use $dirArray[$index] to print out the entire file name so Im completly lost lol. Quote Link to comment Share on other sites More sharing options...
papaface Posted February 25, 2007 Share Posted February 25, 2007 does $dirArray[$index] only have one file name? Quote Link to comment Share on other sites More sharing options...
BrandonE97 Posted February 25, 2007 Author Share Posted February 25, 2007 One name per loop and it changes to another file.extension Quote Link to comment Share on other sites More sharing options...
papaface Posted February 25, 2007 Share Posted February 25, 2007 Post your code for the page you are using this on.. Quote Link to comment Share on other sites More sharing options...
BrandonE97 Posted February 25, 2007 Author Share Posted February 25, 2007 <?php print("<table border=\"1\" cellpadding=\"5\" cellspacing=\"0\" class=\"whitelinks\">\n"); print("<tr><th>Filename</th><th>Filetype</th><th>Filesize</th></tr>\n"); // loop through the array of files and print them all for($index=0; $index < $indexCount; $index++) { // this if was in the original code I found and hides the "." ".." and ".htaccess" from showing in the listing if (substr("$dirArray[$index]", 0, 1) != ".") { list($fname, $fext) = explode('.', $dirArray['$index']); // the $IGfname and $IGfext are arrays of names/extensions not to show in the listing if ($fname != $IGfname || $fext != $IGfext) { print("<tr><td><a href=\"$DLdir$dirArray[$index]\" target=\"_blank\">$dirArray[$index]</a></td>"); print("<td>"); print($fext); print("</td>"); print("<td>"); // this is using a function to give the size in bytes, kb, mb, or gb print(myFileSize(filesize("$DLdir$dirArray[$index]"))); print("</td>"); print("</tr>\n"); } } } ?> Quote Link to comment Share on other sites More sharing options...
papaface Posted February 25, 2007 Share Posted February 25, 2007 If when you echo it out, it is shown without a problem, try doing: $file = $dirArray[$index]; list($fname, $fext) = explode('.', $file); I dont think it will work, but its worth a try. Im stuck on this one, I cant see why it isnt working. Quote Link to comment Share on other sites More sharing options...
BrandonE97 Posted February 25, 2007 Author Share Posted February 25, 2007 I tried that earlier and went and tried it again and it still doesnt work. Thanks for your help on this anyways! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 25, 2007 Share Posted February 25, 2007 Note that $dirArray['$index'] is not the same as $dirArray[$index]. That is probably your problem. You probably want your code to look like: <?php list($fname, $fext) = explode('.', $dirArray[$index]); ?> Ken Quote Link to comment Share on other sites More sharing options...
BrandonE97 Posted February 25, 2007 Author Share Posted February 25, 2007 Ah, I was trying to access a named array variable or associative array instead of and array variable with the number pointer. I see that now lol. Thanks kenrbnsn! Quote Link to comment Share on other sites More sharing options...
BrandonE97 Posted February 25, 2007 Author Share Posted February 25, 2007 Now my script is working like I want. Thanks again you guys. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.