Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. function url2breadcrumb($url,$include_base=1,$home_url=false){
  2. if(empty($url)){
  3. return;
  4. }
  5. $base = parse_url($url);
  6. $base = $base['scheme'].'://'.$base['host'].'/';
  7. $crumbs = rtrim(parse_url($url,PHP_URL_PATH),'_');
  8. $crumbs = array_filter(explode("/",$crumbs));
  9. $link = '';
  10. $breadcrumbs = array();
  11. $exclude = array('.htm','.html','.php'); //will be deleted from crumb text
  12. $replace = array('-','_'); //will be replaced to whitespace
  13. foreach($crumbs as $crumb){
  14.  
  15. //exclude home url
  16. if($home_url){
  17. $h = str_replace($base,'',$home_url);
  18. $h = ltrim($h,'/');
  19. $h = rtrim($h,'/');
  20. if($crumb == $h){
  21. continue;
  22. }
  23. }
  24.  
  25. $link .= $crumb.'/';
  26. $text = str_replace($replace,' ',$crumb);
  27. $the_crumb = array(
  28. 'text'=>ucwords(str_replace($exclude,'',$text)),
  29. 'link'=>($include_base==1?$base:'').rtrim($link,"/")
  30. );
  31. $breadcrumbs[] = $the_crumb;
  32. }
  33. return $breadcrumbs;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement