且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

适用于UTF-8字符串的strtoupper PHP函数

更新时间:2023-11-25 09:56:16

您要使用mb_strtoupper.

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

PHP.net 状态:

与标准情况相反 折叠功能,例如strtolower() 和strtoupper(),大小写折叠为 根据Unicode执行 角色属性.就这样 此功能的行为不是 受区域设置的影响,它可以 转换任何具有 字母"属性,例如 A-变音符(Ä).

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 (Ä).