Hm..
Wrote this a while ago, as a little tool for myself.. Do not know whether it works ;-). In any case, It should get you started.
<?php
// *****************************************************************
// Showfunctions.php, dd: juli 5th 2003, JG Ferwerda, post<at>bio-vision.nl
// This program will go through all the files in a directory, and
// search each file for functions defined & used, and wil list all
// included & required files, on a file-to file basis
// *****************************************************************
// You only need to modify the last 10 lines: Change the path, to
// search a specific folder, or set a specific file to list using
// the last command at the page
// *****************************************************************
function searchused($line) // Find functions used, per line
{
preg_match("#(\S{1,})(\()(.{0,})(\))(.{0,})#", $line, $matches);
$functionname = $matches[1];
$arguments = $matches[3];
$output = $functionname;
return $output;
}
function searchfun($line) // Finds defined functions on a line
{
preg_match("#function (.{0,})(\()(.{0,})(\))(.{0,})#", $line, $matches);
$functionname = $matches[1];
$arguments = $matches[3];
$output[0] = $functionname;
$output[1] = $arguments;
return $output;
}
function searchreq($line) // Finds required files, on a line
{
preg_match("#require\((.{0,})(\))(.{0,})#", $line, $matches);
$result = $matches[1];
return $result;
}
function searchreq_once($line) // Finds required files, on a line
{
preg_match("#require_once\((.{0,})(\))(.{0,})#", $line, $matches);
$result = $matches[1];
return $result;
}
function searchinc($line) // Finds included files, on a line
{
preg_match("#include\((.{0,})(\")(.{0,})(\")(.{0,})#", $line, $matches);
$result = $matches[3];
return $result;
}
function searchinc_once($line) // Finds included files, on a line
{
preg_match("#include_once\((.{0,})(\")(.{0,})(\")(.{0,})#", $line, $matches);
$result = $matches[3];
return $result;
}
function removeduplicates($array) // Sort ar array, removes duplicates,
// and keeps track of the number of original occurances
{
$thisarray = $array;
sort($thisarray);
$tmparray[0] = $thisarray[0];
$tmparray[1] = 1;
$j = 0;
for($i = 1; $i<sizeof($thisarray); $i++)
{
if($thisarray[$i] <> $tmparray[0])
{
$newarray[$j] = $tmparray;
$j++;
$tmparray[0] = $thisarray[$i];
$tmparray[1] = 1;
}
else
{
$tmparray[1] = $tmparray[1] + 1;
}
}
return $newarray;
}
// *** Main function, calls all of the above. ***
function indexpage($page) // Opens a file for reading, reads each line,
// and finds functions, files needed in the script
{
$thispage = $page;
$getpage = array($thispage);
$fp = fopen($getpage[0],"r");
$i = 0;
$j = 0;
$k = 0;
$l = 0;
$numlines = 0;
$numcode = 0;
while(!feof($fp))
{
$line = fgets($fp,1024);
$numlines++;
if(ereg(" include", $line))
{
$included[$k] = searchinc($line);
$k++;
$included[$k] = searchinc_once($line);
$k++;
}
else
{
if(ereg("require", $line))
{
$required[$i] = searchreq($line);
$i++;
$required[$i] = searchreq_once($line);
$i++;
}
else
{
if(ereg("function (.{0,})(\()(.{0,})(\))", $line))
{
$thefunction[$j] = searchfun($line);
$j++;
}
else
{
if(ereg("(.)(\S{0,})(\()(.{0,})(\))", $line))
{
$thisfunct = searchused($line);
if(! $thisfunct == "")
{
$usedfunction[$l] = $thisfunct;
$l++;
}
}
}
}
}
}
fclose($fp);
// Cleanup the used function array
if ( is_string($usedfunctions) )
{
}
else
{
if ( is_array($usedfunction))
{
$usedfunction = removeduplicates($usedfunction);
}
}
// Generate output
echo "------------------ Start of file: $thispage -----------------";
echo "<br><b>".$numlines. " lines </b>";
echo "<table cellspacing=10><tr><td colspan=2><u>Files included</u></td></tr>";
for($x=0; $x<$k; $x++)
{
echo "<tr><td colspan=2>" . $included[$x]."</td></tr>";
}
echo "<tr><td colspan=2><u>Files required</u></td></tr>";
for($x=0; $x<$i; $x++)
{
echo "<tr><td colspan=2>" . $required[$x]."</td></tr>
";
}
echo "<tr><td colspan=2><u>Functions defined</u></td></tr>";
for($x=0; $x<$j; $x++)
{
echo " <tr><td><b>" . $thefunction[$x][0].":</b></td><td> ".$thefunction[$x][1]."</td></tr>
";
}
echo "<tr><td colspan=2><u>Functions used</u></td></tr>";
$l = sizeof($usedfunction);
for($x=0; $x<$l; $x++)
{
echo " <tr><td><b>" . $usedfunction[$x][0]."</b></td><td>" . $usedfunction[$x][1]." time(s)</td></tr>
";
}
echo "</table>------------------ End of file: $thispage -----------------</p>";
} // End of function indexpage
function findfiles($directory, $searchstring) // Finds all files witha certain extention
{
$searchstring = $searchstring;
$dirpath = $directory;
$i = 0;
$dir = opendir($dirpath); // create directory handle
while (false !== ($file = readdir($dir)))
{
if (false !== strpos($file, $searchstring))
{
$files[$i] = $file;
$i++;
}
}
closedir($dir);
return $files;
}
function indexpath($thispath)
{
$path = $thispath;
$filenames = findfiles($path,"php");
$size = sizeof($filenames);
for($t=0; $t<$size; $t++)
{
$page = $path."\\".$filenames[$t];
indexpage($page);
}
}
//*************************************************************
// END OF DECLARATIONS and function definition ****************
// ************************************************************
echo "------------------- Folder Functions -------------------";
indexpath("D:\webroot\\new_hyperspectral\website\database");
echo "------------------- Folder Includes -------------------";
indexpath("D:\webroot\\new_hyperspectral\website\database\includes");
?>