gpt4 book ai didi

php - UTF-8 字符串的 strtoupper PHP 函数

转载 作者:IT王子 更新时间:2023-10-29 01:18:27 32 4
gpt4 key购买 nike

我一直在阅读用户对 strtoupper() PHP 函数的评论,但似乎没有就如何对非英语字符串进行转换达成共识。我的意思是人们提供本地化的解决方案和东西,但难道不应该有一种统一的方法来将字符串转换为所有大写(或所有小写)字母吗?

所以我的问题是,比方说,如果我有一个 UTF-8 编码的字符串(在某些未知的语言环境中),我如何将它转换为 PHP 中的所有大写/小写字母?

最佳答案

您想使用 mb_strtoupper

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

PHP.net状态:

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

关于php - UTF-8 字符串的 strtoupper PHP 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5969803/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com