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. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/ 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. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193412 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. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193418 Share on other sites More sharing options...
papaface Posted February 25, 2007 Share Posted February 25, 2007 What is in $dirArray['$index']? Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193419 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. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193423 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. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193431 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. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193436 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? Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193444 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 Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193445 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.. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193449 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"); } } } ?> Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193452 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. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193456 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! Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193460 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 Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193463 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! Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193465 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. Link to comment https://forums.phpfreaks.com/topic/39991-solved-list-and-split-problem/#findComment-193469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.