ShoeLace1291 Posted November 9, 2007 Share Posted November 9, 2007 I have a page that gets all the php files in a certain folder and displays them. It's a foreach loop, but for some reason I'm getting an infinite loop. This is my code: <?php echo "<table align='center' cellspacing='2' cellpadding='2' border='0'> <tr>"; $rows = 0; foreach(glob('forums/*.php') as $szFilename){ $rows = $rows + 1; echo "<td style='text-align: center;'><img src='images/icon_phpfile.png' alt='PHP File'><br>$szFilename</td>"; if($rows == { echo "</tr><tr>"; } } echo "</tr></table>"; ?> Link to comment https://forums.phpfreaks.com/topic/76656-infinite-loop-in-glob-function/ Share on other sites More sharing options...
Orio Posted November 9, 2007 Share Posted November 9, 2007 Should be a problem here.... Try: <?php echo "<table align='center' cellspacing='2' cellpadding='2' border='0'> <tr>"; $rows = 0; $files = glob('forums/*.php'); foreach($files as $szFilename){ $rows = $rows + 1; echo "<td style='text-align: center;'><img src='images/icon_phpfile.png' alt='PHP File'><br>$szFilename</td>"; if($rows == { echo "</tr><tr>"; } } echo "</tr></table>"; ?> Orio Link to comment https://forums.phpfreaks.com/topic/76656-infinite-loop-in-glob-function/#findComment-388112 Share on other sites More sharing options...
kenrbnsn Posted November 9, 2007 Share Posted November 9, 2007 I noticed two problems with your code. 1) You should increment the counter after formating the line 2) You should test if the remainder of the $rows / 8 is 0 Try: <?php echo "<table align='center' cellspacing='2' cellpadding='2' border='0'> <tr>"; $rows = 0; foreach(glob('*.php') as $szFilename){ echo "<td style='text-align: center;'><img src='images/icon_phpfile.png' alt='PHP File'><br>$szFilename</td>"; $rows++; if($rows % 8 == 0) echo "</tr><tr>"; } echo "</tr></table>"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/76656-infinite-loop-in-glob-function/#findComment-388143 Share on other sites More sharing options...
ShoeLace1291 Posted November 10, 2007 Author Share Posted November 10, 2007 Is there any way to display the filename without the name of the directory in front of it? so instead of forums/index.php would display as just index.php. Also, what arguement would I use for the first one if I only want to get the name of a directory? glob('here', GLOB_ONLYDIR); Link to comment https://forums.phpfreaks.com/topic/76656-infinite-loop-in-glob-function/#findComment-388439 Share on other sites More sharing options...
Orio Posted November 10, 2007 Share Posted November 10, 2007 Check dirname() and basename(). Orio. Link to comment https://forums.phpfreaks.com/topic/76656-infinite-loop-in-glob-function/#findComment-388490 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.