Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function url2breadcrumb($url,$include_base=1,$home_url=false){
- if(empty($url)){
- return;
- }
- $base = parse_url($url);
- $base = $base['scheme'].'://'.$base['host'].'/';
- $crumbs = rtrim(parse_url($url,PHP_URL_PATH),'_');
- $crumbs = array_filter(explode("/",$crumbs));
- $link = '';
- $breadcrumbs = array();
- $exclude = array('.htm','.html','.php'); //will be deleted from crumb text
- $replace = array('-','_'); //will be replaced to whitespace
- foreach($crumbs as $crumb){
- //exclude home url
- if($home_url){
- $h = str_replace($base,'',$home_url);
- $h = ltrim($h,'/');
- $h = rtrim($h,'/');
- if($crumb == $h){
- continue;
- }
- }
- $link .= $crumb.'/';
- $text = str_replace($replace,' ',$crumb);
- $the_crumb = array(
- 'text'=>ucwords(str_replace($exclude,'',$text)),
- 'link'=>($include_base==1?$base:'').rtrim($link,"/")
- );
- $breadcrumbs[] = $the_crumb;
- }
- return $breadcrumbs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement