<?php

/**
 * Stylize Last Breadcrumb: Takes a pipe-separated breadcrumb string and encapsulates the last crumb with supplied HTML tag
 *
 * @param required string $input
 * @param optional string $html_tag
 * @return string
 */
function stylize_last_breadcrumb($input,$html_tag='em')
{
    
$output '';
    if(
is_string($input))
    {
        if(!
is_string($html_tag) || empty($html_tag))
            
$html_tag 'em';
        
$first_tag_char substr($html_tag,0,1);
        
$tag_was_passed = !!($first_tag_char=='<');
        
$start_style_tag $tag_was_passed $html_tag "<$html_tag>";
        
$end_style_tag $tag_was_passed str_replace('<','</',$html_tag) : "</$html_tag>";

        
$pattern_to_stylize '/(\|\s*)([^|]*)$/';
        
$stylized_replacement '$1'.$start_style_tag.'$2'.$end_style_tag;
        
$output preg_replace($pattern_to_stylize,$stylized_replacement,$input);
    }
    return 
$output;
}


//Examples
?>
<h1>Example outputs:</h1>
<ul>
    <li><?=stylize_last_breadcrumb('Section | Page Name')?></li>
    <li><?=stylize_last_breadcrumb('Section | Page Name','span')?></li>
    <li><?=stylize_last_breadcrumb('Site | Section | Page Name')?></li>
    <li><?=stylize_last_breadcrumb('Site | Section | Page Name','strong')?></li>
    <li><?=stylize_last_breadcrumb('Site | Section | Page Name','<span>')?></li>
</ul>

<p>(View source to see what tags were applied) -- <a href="source.php">See the code...</a></p>