Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] non latin chars to latin chars
#1

[eluser]SPeed_FANat1c[/eluser]
Hi,

Code:
function test()
    {
        $word = 'ąčę';
        
        
        $word = utf8_decode($word);


        
        for($i=0;$i<strlen($word);$i++)
        {
                    
            echo $word[$i];
            
        }
        
         $this->load->view('test/test');
        
    }

I actually want to convert strings like this:

'ąąčąę' => aacae

but I get '?' when I want to get those non latin chars. At first even strlen did not get corrent count of char, but then I used google and found that utf8_decode helps to do it. Maybe some of you could help me solve my problem?
#2

[eluser]WanWizard[/eluser]
You can't use utf_decode() for this purpose, it is used for characterset conversion, it doesn't alter the 'meaning' of individual characters.

Try:
Code:
function normalize ($string) {
    $table = array(
        'Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c',
        'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
        'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O',
        'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss',
        'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e',
        'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o',
        'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b',
        'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r',
    );
  
    return strtr($string, $table);
}
You can extend the array if you need to convert other characters.
#3

[eluser]SPeed_FANat1c[/eluser]
thank you, this is what I needed Smile




Theme © iAndrew 2016 - Forum software by © MyBB