Reply to Re: problem returning value using recursive function

Your name:

Reply:


Posted by Steve on 04/12/07 17:03

alright, so i've got some free-time. ;^)

i'm guessing your function recurses to 1) find that a directory exists and
2) find out how deeply nested it is. based on that, this should work just
fine:

<?
function combinePath(&$directory, $index, $path)
{
$directory = $path . '/' . $directory;
}

function getDirectories($path, &$tree = array())
{
$tree[$path] = $path;
$directory = opendir($path);
while (($fileName = readdir($directory)) !== false)
{
if ($fileName == '.' || $fileName == '..'){ continue; }
if (!is_dir($fileName)){ continue; }
$directories[] = $fileName;
}
closedir($directory);
if (!$directories){ return $tree; }
array_walk($directories, 'combinePath', $path);
foreach ($directories as $directory)
{
getDirectories($directory, $tree);
}
return $tree;
}

$path = 'c:/inetpub/wwwroot/someserver';
$testPath = 'c:/inetpub/wwwroot/someserver/css';
$directories = getDirectories($path);
$level = 0;
if (in_array($testPath, $directories))
{
$testPath = substr($testPath, strlen($path));
$level = strlen($testPath) - strlen(str_replace('/', '', $testPath));
}
echo '<pre>' . $level . '</pre>';
?>

you may now turn this to shit at will. :)

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация