home *** CD-ROM | disk | FTP | other *** search
Wrap
Menus from Directories This is a dynamically generated menu system, that reads from directories .HTML and .php3 files, with a <TITLE> tag on a seperate line. This is a hack for what I needed, but I though it may be useful, you can see it in action at www.action-web.net <?php function echo_link($link, $text, $directory_) { echo "<FONT size=2> <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($fp, 1024); /* 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(); } ?>