Autor Zpráva
lenkali
Profil *
Dobrý den, prosím Vás o pomoc při odstranění diakritiky ze slova:


Odstranění diakritiky ze slova:"Žabíškleb" přepsat na slovo:"zabiskleb"

Do formuláře do policka zvireciskleb zadám slovo :"Žabíškleb", které na další stránce načtu do proměnné:
$zvire= $_REQUEST['zvireciskleb'];

Jak mám udělat prosím to, aby když uložím do proměnné slovo "Žabíškleb",
aby se mi vypsalo v příkazu

echo $zvire;

jen "zabiskleb" Všechny písmenka malé a bez diakritiky..

prosím o pomoc
nightfish
Profil
http://latrine.dgx.cz/odstraneni-diakritiky-z-ruznych-kodovani
+ strtolower()
lenkali
Profil *
NIGHTFISHI, dekuji


nasla jsem z Tveho odkazu tohle a ktera promenna je ta moje $zvire:






<?php


// WINDOWS-1250 to ASCII for diacritic chars
function cs_win2ascii($s)
{
return strtr($s, "\xe1\xe4\xe8\xef\xe9\xec\xed\xbe\xe5\xf2\xf3\xf6\xf5\xf4\xf8\xe0\x9a\ x9d\xfa\xf9\xfc\xfb\xfd\x9e\xc1\xc4\xc8\xcf\xc9\xcc\xcd\xbc\xc5\xd2\xd 3\xd6\xd5\xd4\xd8\xc0\x8a\x8d\xda\xd9\xdc\xdb\xdd\x8e", "aacdeeillnoooorrstuuuuyzAACDEEILLNOOOORRSTUUUUYZ");

}


// ISO-8859-2 to ASCII for diacritic chars
function cs_iso2ascii($s)
{
return strtr($s, "\xe1\xe4\xe8\xef\xe9\xec\xed\xb5\xe5\xf2\xf3\xf6\xf5\xf4\xf8\xe0\xb9\ xbb\xfa\xf9\xfc\xfb\xfd\xbe\xc1\xc4\xc8\xcf\xc9\xcc\xcd\xa5\xc5\xd2\xd 3\xd6\xd5\xd4\xd8\xc0\xa9\xab\xda\xd9\xdc\xdb\xdd\xae", "aacdeeillnoooorrstuuuuyzAACDEEILLNOOOORRSTUUUUYZ");

}


// UTF-8 to ASCII for diacritic chars
function cs_utf2ascii($s)
{
static $tbl = array("\xc3\xa1"=>"a","\xc3\xa4"=>"a","\xc4\x8d"=>"c","\xc4\x8f"=>"d", "\xc3\xa9"=>"e","\xc4\x9b"=>"e","\xc3\xad"=>"i","\xc4\xbe"=>"l","\xc4\ xba"=>"l","\xc5\x88"=>"n","\xc3\xb3"=>"o","\xc3\xb6"=>"o","\xc5\x91"=> "o","\xc3\xb4"=>"o","\xc5\x99"=>"r","\xc5\x95"=>"r","\xc5\xa1"=>"s","\ xc5\xa5"=>"t","\xc3\xba"=>"u","\xc5\xaf"=>"u","\xc3\xbc"=>"u","\xc5\xb 1"=>"u","\xc3\xbd"=>"y","\xc5\xbe"=>"z","\xc3\x81"=>"A","\xc3\x84"=>"A ","\xc4\x8c"=>"C","\xc4\x8e"=>"D","\xc3\x89"=>"E","\xc4\x9a"=>"E","\xc 3\x8d"=>"I","\xc4\xbd"=>"L","\xc4\xb9"=>"L","\xc5\x87"=>"N","\xc3\x93" =>"O","\xc3\x96"=>"O","\xc5\x90"=>"O","\xc3\x94"=>"O","\xc5\x98"=>"R", "\xc5\x94"=>"R","\xc5\xa0"=>"S","\xc5\xa4"=>"T","\xc3\x9a"=>"U","\xc5\ xae"=>"U","\xc3\x9c"=>"U","\xc5\xb0"=>"U","\xc3\x9d"=>"Y","\xc5\xbd"=> "Z");
return strtr($s, $tbl);
}



?>
Davex
Profil
lenkali
Jsou to funkce, takže si vyber jednu z nich podle kódování stránky a použij ji následovně:
$zvire = cs_utf2ascii( $_REQUEST['zvireciskleb'] );
lenkali
Profil *
Je to takto zakomponovano spravne Davexi nebo Nightfishi, prosim?
Porad se mi totiz vypisuje to co napisu, i s diakritikou...
$zvire= $_REQUEST['zvireciskleb']; 

// UTF-8 to ASCII for diacritic chars
function cs_utf2ascii($zvire)
{
    static $tbl = array("\xc3\xa1"=>"a","\xc3\xa4"=>"a","\xc4\x8d"=>"c","\xc4\x8f"=>"d",  "\xc3\xa9"=>"e","\xc4\x9b"=>"e","\xc3\xad"=>"i","\xc4\xbe"=>"l","\xc4\  xba"=>"l","\xc5\x88"=>"n","\xc3\xb3"=>"o","\xc3\xb6"=>"o","\xc5\x91"=>  "o","\xc3\xb4"=>"o","\xc5\x99"=>"r","\xc5\x95"=>"r","\xc5\xa1"=>"s","\  xc5\xa5"=>"t","\xc3\xba"=>"u","\xc5\xaf"=>"u","\xc3\xbc"=>"u","\xc5\xb  1"=>"u","\xc3\xbd"=>"y","\xc5\xbe"=>"z","\xc3\x81"=>"A","\xc3\x84"=>"A  ","\xc4\x8c"=>"C","\xc4\x8e"=>"D","\xc3\x89"=>"E","\xc4\x9a"=>"E","\xc  3\x8d"=>"I","\xc4\xbd"=>"L","\xc4\xb9"=>"L","\xc5\x87"=>"N","\xc3\x93"  =>"O","\xc3\x96"=>"O","\xc5\x90"=>"O","\xc3\x94"=>"O","\xc5\x98"=>"R",  "\xc5\x94"=>"R","\xc5\xa0"=>"S","\xc5\xa4"=>"T","\xc3\x9a"=>"U","\xc5\  xae"=>"U","\xc3\x9c"=>"U","\xc5\xb0"=>"U","\xc3\x9d"=>"Y","\xc5\xbd"=>  "Z");
    return strtr($zvire, $tbl);
}

$zvire = cs_utf2ascii( $_REQUEST['zvireciskleb'] )

echo $zvire;
nightfish
Profil
tohle bude fungovat za předpokladu, že stránky jsou v kódování UTF-8
není-li tomu tak, je potřeba použít funkci podle kódování - tedy cs_win2ascii pro windows-1250 nebo cs_iso2ascii pro iso-8859-2
function cs_utf2ascii($s)
{
static $tbl = array("\xc3\xa1"=>"a","\xc3\xa4"=>"a","\xc4\x8d"=>"c","\xc4\x8f"=>"d",  "\xc3\xa9"=>"e","\xc4\x9b"=>"e","\xc3\xad"=>"i","\xc4\xbe"=>"l","\xc4\  xba"=>"l","\xc5\x88"=>"n","\xc3\xb3"=>"o","\xc3\xb6"=>"o","\xc5\x91"=>  "o","\xc3\xb4"=>"o","\xc5\x99"=>"r","\xc5\x95"=>"r","\xc5\xa1"=>"s","\  xc5\xa5"=>"t","\xc3\xba"=>"u","\xc5\xaf"=>"u","\xc3\xbc"=>"u","\xc5\xb  1"=>"u","\xc3\xbd"=>"y","\xc5\xbe"=>"z","\xc3\x81"=>"A","\xc3\x84"=>"A  ","\xc4\x8c"=>"C","\xc4\x8e"=>"D","\xc3\x89"=>"E","\xc4\x9a"=>"E","\xc  3\x8d"=>"I","\xc4\xbd"=>"L","\xc4\xb9"=>"L","\xc5\x87"=>"N","\xc3\x93"  =>"O","\xc3\x96"=>"O","\xc5\x90"=>"O","\xc3\x94"=>"O","\xc5\x98"=>"R",  "\xc5\x94"=>"R","\xc5\xa0"=>"S","\xc5\xa4"=>"T","\xc3\x9a"=>"U","\xc5\  xae"=>"U","\xc3\x9c"=>"U","\xc5\xb0"=>"U","\xc3\x9d"=>"Y","\xc5\xbd"=>  "Z");
return strtr($s, $tbl);
} 

$zvire = $_REQUEST['zvireciskleb'];
$zvire = cs_utf2ascii($zvire);
$zvire = strtolower($zvire);
echo $zvire;


P.S.: pro výpis kódu používej značku "pre" - vloží se pomocí tlačítka "<>" nad odpovídacím formulářem
lenkali
Profil *
Vyzkousim to, dekuji moc NIGHTFISHI za Tvuj cas
TSD
Profil *
Nemůžu si pomoct, mkdysi jsem udělal něco, co mi připadá jaksi přehlednější:

function odstraneni_diakritiky($text_bez_diakritiky)
{
  $a = array("á","ä","č","ď","é","ě","ë","í","ň","ó","ö","ř","š","ť","ú","ů", "ü","ý","ž","Á","Ä","Č","Ď","É","Ě","Ë","Í","Ň","Ó","Ö","Ř","Š","Ť","Ú ","Ů","Ü","Ý","Ž"); 
  $b = array("a","a","c","d","e","e","e","i","n","o","o","r","s","t","u","u", "u","y","z","A","A","C","D","E","E","E","I","N","O","O","R","S","T","U ","U","U","Y","Z"); 
  $vysledny_text = str_replace($a, $b, $text_bez_diakritiky);
  return $vysledny_text;
}
TSD
Profil *
fórum si to přebralo trochu jinak, mezera k "Ú " ani "U " nepatří.
nightfish
Profil
TSD
sice přehlednější, ale oproti výše uvedenému řešení závislé na kódování
Davex
Profil
TSD
Souhlasím s nightfishem a dodávám, že funkce strtr() je mnohem rychlejší než str_replace().
TSD
Profil *
nezávislost na kódování chápu, ale netrápí mě.
rychlost jsem netušil

Takže jsem poradil a ještě na tom vydělal, díky :)
lenkali
Profil *
Funguje to nádherně, děkuji všem za pomoc a za Váš čas......
NIGHTFISH, DAVEX, TSD

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0