PHP中字符串大小写转换 心已赠人 2022-07-27 15:00 138阅读 0赞 ucfirst() 函数把字符串中的首字符转换为大写。 例如: $str="hello world"; echo ucfirst($str); 运行结果为: Hello world ### 相关函数: ### * [lcfirst()][lcfirst] \- 把字符串中的首字符转换为小写 * [strtolower()][strtolower] \- 把字符串转换为小写 * [strtoupper()][strtoupper] \- 把字符串转换为大写 * [ucwords()][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以上就可以 如果所转化的字符串中含有中文或数字,则中文和数字保持原样。 [lcfirst]: http://www.w3school.com.cn/php/func_string_lcfirst.asp [strtolower]: http://www.w3school.com.cn/php/func_string_strtolower.asp [strtoupper]: http://www.w3school.com.cn/php/func_string_strtoupper.asp [ucwords]: http://www.w3school.com.cn/php/func_string_ucwords.asp
还没有评论,来说两句吧...