0
<?php
function breadcrumbs($home = 'Ana Sayfa') {
//Use RDFa breadcrumb, can also be used for microformats etc.
$bc     =   '';
$isaret = ' &raquo';
//Get the website:
$site   =   'http://'.$_SERVER['HTTP_HOST'];

//Get all vars en skip the empty ones
$crumbs =   array_filter( explode("/",$_SERVER["REQUEST_URI"]) );
//Create the home breadcrumb
$bc    .=   '<li><a href="'.$site.'" rel="v:url" property="v:title">'.$home.''.$isaret.'</a></li>'; 
//Count all not empty breadcrumbs
$nm     =   count($crumbs);
$i      =   1;
//Loop the crumbs
foreach($crumbs as $crumb){
    $link    =  ucfirst( str_replace( array(".php","-","_"), array(""," "," ") ,$crumb) );
    $site   .=  '/'.$crumb;
    //Make the next crumb
    $bc     .=  '<li><a href="'.$site.'" rel="v:url" property="v:title">'.$link.''.$isaret.'</a></li>';
    $i++;
}
$bc .=  '';
//Return the result
return $bc;}

?>

Hello There

I am using in my web sites this great Php dynamic bredcrump solution which was an answer in this post. Thank you for sharing. But i have a question;

In my site i am using Turkish language, and Turkish language has 7 non-english letter in it's alphaphet.so when the script copy the adress bar breadcrump shows only english compatible letters unfortunattely not turkish letters.

Question is : With this script is it possible the create a variable that allows to tweak and show created link's title in breadcrump menu

For example :

Adress Bar=

http://www.mamaia.com/tr/urunler/cocuk-uretimi-alcilar

Breadcrump = (should be)

Ana Sayfa > Tr > Ürünler > Çocuk Üretimi Alçılar

is there any suggestions?

Community
  • 1
  • 1
nova
  • 1
  • I am not sure that `ucfirst()` is multibyte-encoding safe, `Note that 'alphabetic' is determined by the current locale. For instance, in the default "C" locale characters such as umlaut-a (ä) will not be converted.` http://us2.php.net/manual/en/function.ucfirst.php p.s. Your language letters are not present in url so script will not display them anyway. – Sergiy T. Feb 09 '14 at 11:56
  • Thank you Sergiy, you are correct that script only copy and shows the what adress bar have. So adress bar simply doesn't support non-english letters. I just trying to add a variable to created links's titles which i can manually control when it's created.or may be another solutin – nova Feb 09 '14 at 12:11
  • Actually non-basic characters are supported in address bar (see wikipedia for example). But it is more difficulties and to my mind it's better to use basic characters if you can. You may store array of names like `$page_titles['url_name']='real_name';` somewhere in config-file and than select corresponding values from that array. – Sergiy T. Feb 09 '14 at 12:47
  • Browsers don't have any problem at making HTTP requests when you type non-ASCII characters in the address bar, and you can encode the href in the generated response - see my answer for an example with code. However I don't like the approach of deriving a pretty description from the HTTP request, because it's really a separate piece of input. You'd better redesign your internal routing – Raffaele Feb 10 '14 at 14:33
  • yes, i can't get a proper solution for this, so i will change my breadcrumb, thanks all by the way. – nova Feb 10 '14 at 22:09

2 Answers2

1

1) Set content encoding inside <head></head> tags

<meta charset="utf-8">

2) Set this at the top

setlocale(LC_ALL, 'tr_TR.UTF-8')

3) If still problems, try

 echo utf8_encode($your_breadcrumb);
0

This is a two-steps process in PHP, which is a language with binary strings:

  1. Get the input right: browsers use UTF-8 to percent-encode the bytes of the URI in the request line of the HTTP request. After the PHP engines has decoded the URI you have a string of UTF-8 characters in your script, and since UTF8 is a variable-length encoding, you can't use plain string functions (str_replace, ucfirst) when manipulating the input. Use the multibyte versions instead, and always provide UTF-8 as the encoding.

  2. Get the output right. You must choose en encoding suitable for Turkey: UTF-8 is an option, but CP1254 works as well. Output the encoding header before anything else, then make sure that the static parts of the text are encoded with the very same scheme, and finally convert the dynamic snippets from UTF-8 to your target encoding. Note that the href attribute of links can't contain non-ascii characters, so you must rawurlencode parts yourself.

I put online a gist, using mod_rewrite to handle every request with a single file.

Raffaele
  • 20,627
  • 6
  • 47
  • 86