Ozgun Ozgun - 2 months ago 16
PHP Question

php capitalizing uppercase word

I have a Turkish string : HAKKIMIZDA and i am trying to convert to Hakkımızda.

But it converts I character to i. So i look like : Hakkimizda.

How can i convert 'İ' to 'i' and 'I' to 'ı' char ?

$title = ucfirst(mb_strtolower($response["data"]["title"], 'utf-8'));


Also i tried to
mb_detect_encoding($response["data"]["title"])
instead of
'utf-8'
. But nothing changed.

Also i tried to
strtolower
instead of
mb_strtolower

Answer

This solution is not legit but it works ;)

$title = "HAKKIMIZDAKİLER";
$modifedTitle = preg_replace(
    array("/[I]/u", "/[İ]/u"),
    array("ı","i"),
    $title
);

echo $modifedTitle."\n";
mb_internal_encoding("utf-8");
echo ucfirst(mb_strtolower($modifedTitle));
Comments