The following code generates category links for me by taking the value of the URL.
<?php
$trail = array(
'path' => 'Cool Stuff',
'to' => 'Animals',
'a' => 'Spiders'
);
$url = 'example.com/productos/belleza-mujer/perfume-de-mujer ';
$parts = parse_url($url);
$path = pathinfo($parts['path']);
$segments = explode('/', trim($path['dirname'],'/'));
$breadcrumbs[] = '<a href="/">Home</a>';
$crumb_path = '';
foreach ($segments as $segment) {
$crumb_path .= '/' . $segment;
$value = (array_key_exists($segment, $trail)) ? $trail[$segment] : ucfirst($segment);
$breadcrumbs[] = '<a href="' . $crumb_path . '">' . ucwords(str_replace(['_', '-', '+'], ' ', $value)) . '</a>';
}
$breadcrumbs[] = ucwords(str_replace(['_', '-', '+'], ' ',
$path['filename']));
$breadcrumbs = implode(' » ', $breadcrumbs);
echo $breadcrumbs
?>
As a result it gives me the following information:
But what changes should be modified or removed to have a category-only print result like this:
Home » Products » Beauty Woman
Or how it avoided taking the last value.
I think it would be easy for you if you remove the last value of the array you have before performing the implode
switch to