适用于UTF-8字符串的strtoupper PHP函数 [英] strtoupper PHP function for UTF-8 string

查看:107
本文介绍了适用于UTF-8字符串的strtoupper PHP函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关strtoupper()PHP函数的用户注释,并且在如何对非英语字符串进行转换方面似乎还没有达成共识.我的意思是人们提供本地化的解决方案和内容,但是不应该采用统一的方式将字符串转换为所有大写(或所有小写)字母吗?

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 offer localized solutions and stuff, but shouldn't there be a uniform way to convert a string to all upper (or all lower) case letters?

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

So my question is, say, if I have a UTF-8 encoded string (in some unknown locale) how do I convert it to all upper/lower letters in PHP?

推荐答案

您要使用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 (Ä).

这篇关于适用于UTF-8字符串的strtoupper PHP函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆