php 字符串大小写转换

mb_convert_case

mb_convert_case — 对字符串进行大小写转换

mb_convert_case ( string $str , int $mode [, string $encoding = mb_internal_encoding() ] )
  • 1

对一个 string 进行大小写转换,转换模式由 mode 指定。

参数 :
str  要被转换的 string。
mode  转换的模式。它可以是 MB_CASE_UPPER、 MB_CASE_LOWER 和 MB_CASE_TITLE 的其中一个。
 MB_CASE_UPPER : 字符串全部大写
 MB_CASE_LOWER : 字符串全部小写
 MB_CASE_TITLE : 字符串各单词首字母大写
encoding  参数为字符编码。如果省略,则使用内部字符编码。

返回值 :
按 mode 指定的模式转换 string 大小写后的版本。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

注意:

和类似 strtolower()strtoupper() 的标准大小写转换函数相比, 大小写转换的执行根据 Unicode 字符属性的基础。 因此此函数的行为不受语言环境(locale)设置的影响,能够转换任意具有“字母”属性的字符,例如元音变音A(Ä)。
  • 1

范例:

<?php
    $str = "mary had a Little lamb and she loved it so";
    $str = mb_convert_case($str, MB_CASE_UPPER, "UTF-8");
    echo $str; // 输出 MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
    $str = mb_convert_case($str, MB_CASE_TITLE, "UTF-8");
    echo $str; // 输出 Mary Had A Little Lamb And She Loved It So
?>

猜你喜欢

转载自blog.csdn.net/zhaowj0507/article/details/53490659