牛骨文教育服务平台(让学习变的简单)
博文笔记

PHP中字符串大小写转换

创建时间:2016-03-24 投稿人: 浏览次数:4308

ucfirst() 函数把字符串中的首字符转换为大写。

例如:

$str="hello world";
echo ucfirst($str);

运行结果为:

Hello world

相关函数:

  • lcfirst() - 把字符串中的首字符转换为小写
  • strtolower() - 把字符串转换为小写
  • strtoupper() - 把字符串转换为大写
  • ucwords() - 把字符串中每个单词的首字符转换为大写


//将字符串中的首字符转换为小写

$str="HELLO WORLD";
echo lcfirst($str)."<br>";

运行结果为: hELLO WORLD


//将整个字符串转换为小写

$str="HELLO WORLD";
echo strtolower($str)."<br>";

运行结果为:
hello world


//将整个字符串转换为大写

$str="hello WORLD";
echo strtoupper($str)."<br>";

运行结果为:
HELLO WORLD


//将字符串中每个单词的首字符转换为大写
$str="hello world";
echo ucwords($str)."<br>";

运行结果为:
Hello World


注:
lcfirst函数需要php5.3以上的版本才能支持,其他的都是php4.0以上就可以
如果所转化的字符串中含有中文或数字,则中文和数字保持原样。




声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。