views:

33

answers:

1

hey guys, i wonder if you could help me building a little breadcrumb path with php.

        print $path; // /folder/subfolder/subfolder/etc
    // breadcrumb path
    $crumb = explode("/", $path);
    print "<div class='breadcrumbs'>";
    foreach($crumb as $value) {
        print "<a href='?p=". $value ."'>$value</a> &gt; ";
    }
    print "</div>";

the breadcrumbs get printed exactly the way i want them, however i've no idea how i could link every breadcrumb to it's relative path.

e.g. if the current $path is /folder/subfolder/subfolder/etc the the first link (folder) would link to ?p=folder, the second link (subfolder) would link to ?p=subfolder and so on. however the second link has to be ?p=folder/subfolder and not just ?p=folder.

any idea how i could solve that?

+2  A: 
$crumb = explode("/", $path);
print "<div class='breadcrumbs'>";
$newpath = '';
foreach($crumb as $value) {
    $newpath .= $value;
    print "<a href='?p=". $newpath ."'>$value</a> &gt; ";
    $newpath .= '/';
}
print "</div>";
nathan