<?php

/**
* Kleine Funktion zum Erzeugen einer Brotkrümelmavigation
* @author: Jörg Reinholz, fastix WebDesign & Consult, Kassel - http://www.fastix.org/
* @version: 1.0.1
*
* string  $sPath       # The Path # Not optional.
* boolean $bolLastLink # Returm last element as Link?   # Default: false
* string  $sPrePath    # The path bevore the output     # Default: ''
* string  $cDelimOut   # The delimiter into the output. # Default: '/'
* string  $cDelInput   # The delimiter into the input.  # Default: '/'
**/

function getBreadcrumb( $sPath, $bolLastLink=false, $sPrePath='', $cDelimOut='/', $cDelimInput='/' ) {

    $out  = '';
    $path = trim(trim($sPath, $cDelimInput));
    $ar   = explode( $cDelimInput, $path );
    $step = 0;
    $lnk  = $sPrePath;
    foreach($ar as $s) {
        $step++;
        $txt =  htmlspecialchars($s);
        $lnk .= '/' . rawurlencode($s);
        if ( $bolLastLink or count($ar) > $step ) {
            $out .= $cDelimOut . '<a href="' . $lnk .'">' . $txt . '</a>';
        } else {
            $out .= $cDelimOut . $txt;
        }
    }
    $s = array();  $s = array();
    $s[] = '\\' ;  $r[] = '\\\\';
    $s[] = '/'  ;  $r[] = '\/';
    $s[] = '?'  ;  $r[] = '\?';
    $s[] = '+'  ;  $r[] = '\+';
    $s[] = '*'  ;  $r[] = '\*';
    $s[] = '.'  ;  $r[] = '\.';
    $s[] = '('  ;  $r[] = '\(';
    $s[] = ')'  ;  $r[] = '\)';
    $s[] = '['  ;  $r[] = '\[';
    $s[] = ']'  ;  $r[] = '\]';
    $s[] = '{'  ;  $r[] = '\{';
    $s[] = '}'  ;  $r[] = '\}';

    return preg_replace('/^' . str_replace($s, $r, $cDelimOut) . '/' , '' , $out);
}