简体   繁体   中英

UTF-8 is encoding not working in PHP

8 encoding is not working when i am fetching data from mysql table i have some special characters in database unable to fetch some cities with special characters like Østfold city and Ærø so when i type ostfold its not fetching Østfold city from database. while i am perfectly getting Šiauliai and Çorum from db when i write sia and cor respectively.

I have a city table i am getting cities from this table using jquery autocomplete ajax so when I type first three letters it shows me list of related letters I am working in CodeIgniter framwork.

my settings of CodeIgniter database.php :-

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';

My database table city's column setting is :-

city_name(column name)  varchar(100)    utf8_general_ci(Collation)

Please help me anything else i have to change for this why i am unable to get cities starting with this characters like Ø and Æ.

试试这个代码,我希望这可以解决您的问题。

file_exists(mb_convert_encoding("file_å.txt", "UTF-8"));

The collation table does not list Æ to be equal to A, neither does it list Ø to be equal to O.

You don't have an encoding problem (otherwise Çorum = corum wouldn't work), but instead an expectations problem. You expected them to be equal. By the definition of the collation table, they aren't.

See Reference

Ø = O for only one collation: utf8_unicode_520_ci ; most treat it like a letter between O and P . A few collate it after Z .

Æ is a different matter. It collates the same as the two letters AE in utf8_unicode_520_ci and at least one other collation. Otherwise it is between A and B or after Z .

Ç is yet another matter. It is equal to C for all collations except utf8_turkish_ci , in which case it is a letter between C and D .

Š = S for many collations; between S and T for some.

Bottom line: Use utf8_unicode_520_ci for the column and the connection; type Æ as AE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM