PX : code

Menus from Directories by Evan Prentice
Download this code


<?php        
    
function echo_link($link$text$directory_) {
                echo 
"<FONT size=2>&nbsp;&nbsp;&nbsp;<A ";
                echo 
"HREF=\"$directory_$link\" target=\"main\">$text</A></FONT><BR>\r";
        }

/* Call this function from where ever you want generate a menu.
$dir_name is the full local server directory, and $directory is the
web based directory. here is an example.

build_menu("/usr/htdocs/mydocs/","/mydocs/")

*/

    
function build_menu($dir_name$directory) {

        
$d dir($dir_name);
    
chdir($dir_name);
        while(
$file=$d->read()) {

        
/* we don't want this file or any directories, but we do want all
        .html and .phtml files */

        
if ((is_file($file)) && (eregi("html$"$file) or eregi("php3$"$file))) {
        
//if (is_file($file)) {
        //if (eregi("html$", $file)) {
                        
$fp fopen("$file""r");
                        
$build "";
                        
$flag 0;
                        for (
$i 0; !feof($fp); $i++) {
                                
$line fgets($fp1024);

                                
/* The <TITLE> tag MUST be opened at the
                                beginning of a new line */

                                
if (ereg("^<TITLE>"$line))
                                        
$flag 1;
                                if (
$flag == 1)
                                        
$build $build.$line;
                                if (
ereg("</TITLE>"$line))
                                        
$flag 0;
                        }
                        if (
$build "") {
                                
$build ereg_replace("<TITLE>"""$build);
                                
$build ereg_replace("</TITLE>"""$build);
                                
$build trim($build);
                                
echo_link($file$build$directory);
                        }
                }
    }

        
// not sure if this is needed or not, but it does not hurt anything, 
        // for my anyway
    
chdir("/../");

        
// and finally, close the directory
        
$d->close();
    }
?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.