Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Erek

By: a guest on Jun 29th, 2008  |  syntax: PHP  |  size: 1.59 KB  |  hits: 46  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. $protocol = 'http://';
  3. if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "on")
  4. {
  5.    $protocol = 'https://';
  6. }
  7.  
  8. $host = strip_tags($_SERVER['HTTP_HOST']);
  9. // Get the URL, strip any tags for security, remove the protocol and then explode each part into an array.
  10. $url = strip_tags($_SERVER['REQUEST_URI']);
  11. $url = str_replace($protocol, '', $url);
  12. //Remove a trailing slash if there is one
  13. $url = preg_replace('/\/$/', '', $url);
  14. $url = explode('/', $url);
  15.  
  16.  
  17. // Get number of crumbs we'll have.
  18. $crumb_count = count($url);
  19. // Initialize crumb URLs
  20. $crumb_url = $protocol.$host.$url[0].'/';
  21. // Initialize breadcrumbs with Home link
  22. $breadcrumbs = '<a href="'.$crumb_url.'">Home</a>';
  23.  
  24. // Initialize last bool.
  25. $last = FALSE;
  26. // Process each crumb, skipping the first which is Home.
  27. for ($i=1; $i < $crumb_count; ++$i)
  28. {
  29.    if ($i == ($crumb_count-1))
  30.    {
  31.       // End of the line!
  32.       $last = TRUE;
  33.    }
  34.    // Build this crumb's URL.
  35.    $crumb_url .= $url[$i];
  36.    // Add trailing slash if not last crumb
  37.    $crumb_url .= (!$last) ? '/' : '';
  38.    // Replace all dashes and underscores with spaces for URL title.
  39.    $title = str_replace(array('-','_'), array(' ',' '), $url[$i]);
  40.    // uppercase each word and convert all symbols to HTML entities for security.
  41.    $title = htmlentities(ucwords($title), ENT_QUOTES);
  42.    $breadcrumbs .= '&nbsp;>&nbsp;';
  43.    // If not last item, which should be current page, make a link to that crumb, else just show title.
  44.    $breadcrumbs .= (!$last) ? '<a href="'.$crumb_url.'" title="'.$title.'">'.$title.'</a>' : $title;
  45. }
  46. echo $breadcrumbs;
  47. ?>