©
Ce document utilise Manuel du site Web PHP chinois Libérer
(PHP 4 >= 4.3.0, PHP 5)
mb_strtoupper — 使字符串大写
$str
[, string $encoding
= mb_internal_encoding()
] )
将所有的字母字符转化成大写并返回 str
。
str
要大写的 string 。
encoding
encoding
参数为字符编码。如果省略,则使用内部字符编码。
str
里所有的字母都转换成大写的。
更多 Unicode 属性的信息,请参见 » http://www.unicode.org/unicode/reports/tr21/。
和 strtoupper() 不同的是,“字母”是通过 Unicode 字符属性来确定的。 因此这个函数不会受语言环境(locale)设置影响,能够转化任何具有“字母”属性的字符,例如 a 变音符号(?)。
Example #1 mb_strtoupper() 例子
<?php
$str = "Mary Had A Little Lamb and She LOVED It So" ;
$str = mb_strtoupper ( $str );
echo $str ; // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
?>
Example #2 非拉丁 UTF-8 文本的 mb_strtoupper() 例子
<?php
$str = "Τ?χιστη αλ?πηξ βαφ?? ψημ?νη γη, δρασκελ?ζει υπ?ρ νωθρο? κυν??" ;
$str = mb_strtoupper ( $str , 'UTF-8' );
echo $str ; // 打印了 Τ?ΧΙΣΤΗ ΑΛ?ΠΗΞ ΒΑΦ?Σ ΨΗΜ?ΝΗ ΓΗ, ΔΡΑΣΚΕΛ?ΖΕΙ ΥΠ?Ρ ΝΩΘΡΟ? ΚΥΝ?Σ
?>
[#1] Stefan W [2013-08-27 17:44:48]
mb_strtoupper() will not convert the German "?" character into its (relatively new) uppercase form ("?").
mb_strtolower() will, however, convert the uppercase form into a lowercase "?". (tested with PHP 5.5.0)
"SS" is still the most common uppercase presentation of "?". If you want this, you'll have to do it manually:
<?php
mb_internal_encoding("UTF-8");
echo mb_strtoupper("Ma?\n"); // "MA?"
echo mb_strtolower("MA?\n"); // "ma?"
echo mb_strtoupper(str_replace("?", "SS", "Ma?\n")); // "MASS"
?>
[#2] tomasz at trejderowski dot pl [2010-12-29 05:01:47]
Please note, that in many cases, forcing UTF-8 encoding with second parameter is necessary. PHP documentation states that if this parameter is omitted, the internal character encoding value will be used. But in my case it turned out to be not true. Even though I have all my pages encoded in UTF-8 and my DB connection set to force UTF-8 encoding, comparison of user-input and DB-retrieved data, which is using mb_strtoupper, did not work until I forced encoding.
[#3] rai at philscan dot com [2009-08-10 00:33:22]
for some reason, there are instances that special characters do show when you use this function, but when you revisit or refresh the page the special characters doesn't appear anymore, ie GRSARMERING is being displayed instead of GR?SARMERING. You have to provide the second parameter which charset you are using to override the value. in my case it's iso-8859-1, so the function would now look like
mb_strtoupper($foo, 'iso-8859-1')