hi I am using this simple breadcrumb function but i like to exclude certain segments function breadcrumbs(){ $startAtCrumb =3; $url = 'http://www.mydomain.com/projectz/breadcrumbs/'; $bread = explode('/', $_SERVER['REQUEST_URI']); //$excludeSegments $returnString = '<div id="breadcrumbs"><a href='.$url.'>Home</a>'; for($i=$startAtCrumb;$i<count($bread)-1;$i++){ $url.=$bread[$i].'/'; $returnString .= ">> </span> <span class='bc$i'><a href='$url'>" .prettify($bread[$i])."</a>"; } echo $returnString.'</div>'; } Code (markup): I have this solution now $exclude = str_replace('category/','',$_SERVER['REQUEST_URI']); $bread = explode('/', $exclude); Code (markup): But i think i could be better, any suggestions??
There's not really anything out there more generic than that. One thing you could do is pass an array of different breadcrumbs, and also use regular expressions to determine that the full breadcrumb is being taken away. For example, in this string /category/subcategory/product-name.html you would end up with /subproduct-name.html If you use lookaround characters to verify that the character before the start of the crumb name is a / example regex: '%(?<=/)category/%'
@jay6390, tx for your reply, i am stupid when it comes to regex but i see what you mean with your regex example. At the moment i know category is the only one to exclude but you are indeed correct with the subcategory issue. In my case changing str_replace to $exclude = str_replace('/category','',$_SERVER['REQUEST_URI']); Code (markup): should do the trick, right??
Well yes it will work ok for the subcategory, but what about /category/category1/ will change it to 1/ which is the same problem all over again. regex is definitely the way to go