|
Posted by Steve on 02/23/07 04:09
| function inTrail($path, $trail)
| {
| if (!is_array($trail)){ return ''; }
| if (!strlen($path)){ return ''; }
| $match = '';
| $path = explode('/', $path);
| $length = count($trail);
| for ($i = 0; $i < $length; $i++)
| {
| if ($path[$i] != $trail[$i]){ break; }
| $match .= $path[$i] . '/';
| }
| return $match;
| }
i just noticed that $trail is not an exploded path but an array of strings
representing paths. that's an interesting delima because you can have
similar values (paths)...so which should be correct? to make it easy, you
could just do this in your while loop (suppose i should have just kept it
simple ;^):
while (true)
{
if (in_array($path, $trail){ return $path; }
$length = strrpos($path, '/');
if ($length === false){ return false; }
$path = substr($path, 0, $length);
}
that should do it.
Navigation:
[Reply to this message]
|