Question

I have the following code which generates breadcrumbs:

<?php
$output = array();
$chunks = explode('/', $breadcrumbs);
foreach ($chunks as $i => $chunk) {
$output[] = sprintf(
'<a href="index.php?bc=%s">%s</a>',
implode(array_slice($chunks, 0, $i + 1)),
$chunk
);
}

echo implode(' &gt;&gt; ', $output);?>

Right now the $breadcrumbs that are passed through URL are lacking the proper '/' separator between file paths, and I get this: index.php?bc=historymastersdocuments

instead of this: index.php?bc=history/masters/documents/ (which is what I want to see) so my question is how do I append a '/' between my chunks after exploding them and the breadcrumb links should be like this for each chunk

index.php?bc=history -> index.php?bc=history/masters/ -> index.php?bc=history/masters/documents/

Was it helpful?

Solution

You did not provide the glue '/' in your implode call

<?php
$output = array();
$chunks = explode('/', $breadcrumbs);
foreach ($chunks as $i => $chunk) {
    $output[] = sprintf('<a href="index.php?bc=%s">%s</a>', 
                        implode('/', array_slice($chunks, 0, $i + 1)),
                        $chunk);
}

echo implode(' &gt;&gt; ', $output);?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top