strtoupper PHP function for UTF-8 string

后端 未结 2 1966
清酒与你
清酒与你 2020-12-17 08:07

I\'ve been reading user comments for the strtoupper() PHP function and there doesn\'t seem to a consensus on how to do the conversion for non-Enlgish strings. I mean people

2条回答
  •  轮回少年
    2020-12-17 08:47

    You want to use mb_strtoupper.

    $str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
    $str = mb_strtoupper($str, "UTF-8");
    echo $str; // Prints ΤΆΧΙΣΤΗ ΑΛΏΠΗΞ ΒΑΦΉΣ ΨΗΜΈΝΗ ΓΗ, ΔΡΑΣΚΕΛΊΖΕΙ ΥΠΈΡ ΝΩΘΡΟΎ ΚΥΝΌΣ
    

    PHP.net states:

    By contrast to the standard case folding functions such as strtolower() and strtoupper(), case folding is performed on the basis of the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as A-umlaut (Ä).

提交回复
热议问题