Zend - The PHP Company




HTML

Add Code


Automatic test directory links  

Type: code fragment
Added by: bkosse
Entered: 06/12/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 5041
I find myself frequently making various tests/sample sites/etc in PHP that I like to keep around.

This is a code fragment I use to automatically generate a table containing a series of links.


<?php
$path_sep 
'/'// Unix all the way, baby!
$max_print_size 255// more than 255 chars is getting awefully long

$test_dir_path "/home/bkosse/public_html/test";
$file_name "test-description"// description file name
$testdir dir$test_dir_path );

print 
'<TABLE ALIGN="CENTER" CELLPADDING="2" CELLSPACING="0" BORDER="2" WIDTH="50%">' "n";

while(
$entry=$testdir->read()) {
    if( 
$entry == "." || $entry == ".." ) continue;
    
$testing $test_dir_path $path_sep $entry;
    if( !
is_dir$testing ) ) continue;
    
$description_file = @fopen$testing $path_sep $file_name"r" );
    if( 
$description_file ){
        
$description fread$description_file$max_print_size );
        
$description trim$description );
        
$description str_replace"n""<BR>n"$description );
        
fclose$description_file );
    } 
    else {
        
$description "&nbsp;(no description)&nbsp;";
    }
    
    
$display_entry ucwordsstrtr$entry"_"" " ) );
    print 
"<TR>n";
    print 
"<TD WIDTH="30%"><B><A HREF="$entry/">$display_entry";
    print 
"</A></B>&nbsp;&nbsp;</TD>n";
    print 
"<TD WIDTH="70%">$description</TD>n";
    print 
"</TR>n";
}
$testdir->close();

print 
"</TABLE>n";

?>


Usage Example




Rate This Script





Search



This Category All Categories