Error my system not clear the -, of the categories

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

Error my system not clear the -, of the categories



I am implementing a breadcrumb, automatically generated with PHP


<?php
$trail = array(
'path' => 'Cool Stuff',
'to' => 'Animals',
'a' => 'Spiders'
);

$url = 'example.com/products/beauty-woman/fragrance-of-woman/';

$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 . '">' . $value . '</a>';


$breadcrumbs = ucwords(str_replace(['_', '-', '+'], ' ',
$path['filename']));
$breadcrumbs = implode(' &raquo; ', $breadcrumbs);

echo $breadcrumbs

?>



But the output is not what I expected, print the following:



Products » Beauty-woman » Fragrance Of Woman


Products » Beauty-woman » Fragrance Of Woman



But how can I show the following result:



Products » Beauty Woman » Fragrance of woman


Products » Beauty Woman » Fragrance of woman





the str_replace should be happening when you acutally assign the strings to the array. So for $value
– Jeff
15 hours ago


$value





change . $value . to . ucwords(str_replace(['_', '-', '+'], ' ', $value)) .
– Jeff
15 hours ago


. $value .


. ucwords(str_replace(['_', '-', '+'], ' ', $value)) .





@Jeff It's perfect, you can put this like that at the end Fragrance of woman
– Fernando
15 hours ago


Fragrance of woman




1 Answer
1



You don't str_replace() the $value when you actually assign it to the array $breadgrumbs.


str_replace()


$value


$breadgrumbs



So change that line


$breadcrumbs = '<a href="' . $crumb_path . '">' . $value . '</a>';



to


$breadcrumbs = '<a href="' . $crumb_path . '">' . ucwords(str_replace(['_', '-', '+'], ' ', $value)) . '</a>';






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

PySpark count values by condition

Mass disable jenkins jobs