Jump to content

HTML With PHP


Mod-Jay

Recommended Posts

Okay i want line 18's DIV to actually not end on each repeat. im getting confused on how to do it. but everything i try it doesnt work.

1 <?php
2 function getDirectory( $path = '../toplist/', $level = 3 ){ 
3
4     $ignore = array( 'cgi-bin', '.', '..', 'images', 'js', 'css', 'admin'); 
5     $dh = @opendir( $path ); 
6      
7     while( false !== ( $file = readdir( $dh ) ) ){ 
8      //$files = "<div class=\"msg_body\"><a href='edit.php?file=$file'>". $file ."</a> ";
9         if( !in_array( $file, $ignore ) ){ 
10              
11             $spaces = str_repeat( ' ', ( $level * 4 ) ); 
12             if( is_dir( "$path/$file" ) ){ 
13                 echo "<p class=\"msg_head\"><strong>$spaces - $file</strong></p>";
14 // 			    echo "<strong>$spaces - $file<br /></strong>";
15                 getDirectory( "$path/$file", ($level+1) ); 
16             } else { 
17              
18                echo "<div class=\"msg_body\">$spaces $file<br /></div>"; 
19 //				  echo "$spaces $file<br />";
20 				} 
21 
22 				}
23 		
24    } 
25     closedir( $dh );
26 
27 }
29 ?> 

Link to comment
https://forums.phpfreaks.com/topic/235473-html-with-php/
Share on other sites

Is this what you're looking for?  Or does it need to go outside the while statement?

function getDirectory( $path = '../toplist/', $level = 3 ){ 
$ignore = array( 'cgi-bin', '.', '..', 'images', 'js', 'css', 'admin'); 
$dh = @opendir( $path );
while( false !== ( $file = readdir( $dh ) ) ){ 
if( !in_array( $file, $ignore ) ){ 
$spaces = str_repeat( ' ', ( $level * 4 ) );
echo "<div class=\"msg_body\">"; 
if( is_dir( "$path/$file" ) ){ 
echo "<p class=\"msg_head\"><strong>$spaces - $file</strong></p>";
echo "<strong>$spaces - $file<br /></strong>";
getDirectory( "$path/$file", ($level+1) ); 
} else { 
echo "$spaces $file<br />"; 
}//End ELSE	
echo "</div>";
}//END if( is_dir( "$path/$file" )
}//End while( 
closedir( $dh );
}

Link to comment
https://forums.phpfreaks.com/topic/235473-html-with-php/#findComment-1210215
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.