Garth

Jak odstranit diakritiku z proměnné?

Odstranění diakritiky, nebo-li českých znaků, se velmi hodí například při ukládání souborů kdy v názvu nechcete znaky jako "ž", či "š". Na to by bylo vhodné písmeno "ž" nahradit za "z" atd.. jak na to?

1. varianta
  
$nazev_souboru=strtr($nazev_souboru,
"áäčďéěíĺľňóôőöŕšťúůűüýřžÁÄČĎÉĚÍĹĽŇÓÔŐÖŔŠŤÚŮŰÜÝŘŽ",
"aacdeeillnoooorstuuuuyrzAACDEEILLNOOOORSTUUUUYRZ");


2. varianta
  
$utf8table = array
("xc3xa1"=>"a","xc3xa4"=>"a","xc4x8d"=>"c","xc4x8f"=>"d","xc3xa9"=>"e","xc4x9b"=>"e","xc3xad"=>"i","xc4xbe"=>"l","xc4xba"=>"l","xc5x88"=>"n","xc3xb3"=>"o","xc3xb6"=>"o","xc5x91"=>"o","xc3xb4"=>"o","xc5x99"=>"r","xc5x95"=>"r","xc5xa1"=>"s","xc5xa5"=>"t","xc3xba"=>"u","xc5xaf"=>"u","xc3xbc"=>"u","xc5xb1"=>"u","xc3xbd"=>"y","xc5xbe"=>"z","xc3x81"=>"A","xc3x84"=>"A","xc4x8c"=>"C","xc4x8e"=>"D","xc3x89"=>"E","xc4x9a"=>"E","xc3x8d"=>"I","xc4xbd"=>"L","xc4xb9"=>"L","xc5x87"=>"N","xc3x93"=>"O","xc3x96"=>"O","xc5x90"=>"O","xc3x94"=>"O","xc5x98"=>"R","xc5x94"=>"R","xc5xa0"=>"S","xc5xa4"=>"T","xc3x9a"=>"U","xc5xae"=>"U","xc3x9c"=>"U","xc5xb0"=>"U","xc3x9d"=>"Y","xc5xbd"=>"Z");

$nazev_souboru = strtr($nazev_souboru, $utf8table);
 

<< zpět




Nejnovější články