I have problem in PHP converting a string to lowercase when it contains a special char, in this case especially umlauts as i'm dealing with names. The use case here is i'm searching for the name in an array in which the names allready existant in the database are put in lowercase (actually done by strtolower
which works fine).
The Problem is, that converting to lower case fails for special characters, which is very strange as it works with the names from the database and in both cases the input is utf8. I even checked the encoding with mb_detect_encoding($name)
first which returns UTF-8
.
// All names from the database are read into an array, mysql charset is utf8
foreach($db_names as $namerow) {
$name = $namerow['lastname'] .' '. $namerow['firstname'];
$allnames[strtolower($name)] = $namerow['id']; // works
}
// Get data from a webservice which return utf-8 encoded data (i checked that)
$data = ...;
// Test the utf-8
header('Content-Type: text/html; charset=utf-8');
print_r($allnames); // everything is correct here
var_dump(strtolower($data['name'])); // Output i.e. rÖmer - notice still uppercase char
var_dump(mb_strtolower($data['name'])); // Output with strange ? character - r?mer
var_dump(mb_detect_encoding($data['name'])); // Output: UTF-8