Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Site Map Script
#1
PHP Site Map Script

This PHP script generates a list of hyperlinks to all the webpages found below the base directory. The title of each page is extracted for use as the anchor text of the hyperlink. Different formatting styles are easily applied to each directory level such as an indent and font size.

After running the script you can shuffle the links around and delete those you don't want. If you don't want the <li> element to be used, you could replace this with <div> in the code.

Note that this code is for a complete web page so save it as site-mapper.php or similar. You need PHP installed on your web hosting for it to work. View the source of the page to get the code that is produced.


PHP Code:
<html>
<
head>
<
title>Site Map</title>
<!-- 
A php script from UrgentClick.com -->
<
style>
body {font-familyverdanaline-height1.2 }
/* Indent Styles */
.0 text-indent0px;  font-size12ptfont-weightbold }
.1 text-indent20pxfont-size11pt }
.2 text-indent40pxfont-size10pt }
.3 text-indent50pxfont-size8pt }
.4 text-indent60pxfont-size8pt }
.5 text-indent70pxfont-size8pt }
</
style>
</
head>
<
body>
<?
php 
// starting directory. Dot means current directory
$basedir ".";

// function to count depth of directory 
function getdepth($fn){
  return ((
$p strpos($fn"/")) === false) ? : (getdepth(substr($fn$p+1)));
}

// function to print a line of html for the indented hyperlink
function printlink($fn){
  
$indent getdepth($fn); // get indent value
  
echo "<li class=\"$indent\"><a href=\"$fn\">"//print url
    
$handle fopen($fn"r"); //open web page file
    
$filestr fread($handle1024); //read top part of html
    
fclose($handle); //clos web page file
    
if (preg_match("/<title>.+<\/title>/i",$filestr,$title)) { //get page title
        
echo substr($title[0], 7strpos($title[0], '/')-8); //print title
    
} else {
        echo 
"No title";
    }
  echo 
"</a></li><br>\n"//finish html
}

// main function that scans the directory tree for web pages 
function listdir($basedir){
    if (
$handle = @opendir($basedir)) { 
        while (
false !== ($fn readdir($handle))){ 
            if (
$fn != '.' && $fn != '..'){ // ignore these
                
$dir $basedir."/".$fn
                if (
is_dir($dir)){ 
                    
listdir($dir); // recursive call to this function
                
} else { //only consider .html etc. files
                    
if (preg_match("/[^.\/].+\.(htm|html|php)$/",$dir,$fname)) {
                       
printlink($fname[0]); //generate the html code
                    
}
                                } 
            } 
        } 
        
closedir($handle); 
    } 

// function call 
listdir($basedir); //this line starts the ball rolling
?>
</body>
</html> 

Credits and Source: http://www.urgentclick.com/scripts/php-s...cript.html

Thankyou for reading Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  php form script with upload script help andrewjs18 4 3,349 10-07-2010, 11:46 AM
Last Post: JMK940
  Display Google Map based on users location zone 0 557 11-06-2009, 09:57 PM
Last Post: zone

Forum Jump:


Users browsing this thread: 1 Guest(s)