I have a database where encoding is UTF-8 for multilingual purpose.
I this that everything in my app is in UTF-8.
Though I have a problem with the array_key_exists function.
- It starts by a query to the database
SELECT name, value from TABLE
- Then I fill a hash map with the result :
$hashmap[ $row['name'] ] = $row['value']
But when the name in the DB contains accents like ‘é’, the following returns false :
$this->db->select('name');
$this->db->select('value');
$this->db->from('table');
$q = $this->db->get();
$res = $q->result_array();
foreach ($res as $value) {
$hashmap[$value['name']] = $value['value'];
}
$key = 'name é'; // an ord here returns 233
array_key_exists($key, $hashmap)
I dont know how to go further with that, did you encountered the problem ?
I have a performance requirement.
Thanks for your help.
The array key is encoded in UTF-8 if it indeed comes as UTF-8 string from the database. Apparently your source code file is not encoded in UTF-8, I’d guess it’s encoded in Latin-1. A comparison between a UTF-8 byte sequence and a Latin-1 byte sequence is therefore unsuccessful. Save you source code files in UTF-8 and it should work (consult your text editor).