php首字母小写转大写的方法:1、创建一个PHP示例文件;2、使用“ucwords($foo)”方法将每个单词的首字母转换为大写;3、使用“ucfirst($foo);”方法将第一个单词首字母变大写。

本文操作环境: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视频教程》
以上就是php首字母小写怎么转大写的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章!