这篇文章主要介绍“php的首字母小写怎么转大写”,在日常操作中,相信很多人在php的首字母小写怎么转大写问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”php的首字母小写怎么转大写”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
本文操作环境:Windows7系统、PHP7.1版本、Dell G3电脑
php首字母小写怎么转大写?
php首字母小写转大写的方法
每个单词的首字母转换为大写:ucwords()
<?php
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!
$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>
ucwords() 函数把字符串中每个单词的首字符转换为大写。
第一个单词首字母变大写:ucfirst()
<?php
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>
ucfirst() 函数把字符串中的首字符转换为大写。
到此,关于“php的首字母小写怎么转大写”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!