服务器之家

服务器之家 > 正文

PHP将字符串首字母大小写转换的实例

时间:2021-04-15 16:43     来源/作者:PHP教程网

每个单词的首字母转换为大写:ucwords()

?
1
2
3
4
5
6
7
8
<?php
$foo = 'hello world!';
$foo = ucwords($foo);       // Hello World!
 
$bar = 'HELLO WORLD!';
$bar = ucwords($bar);       // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>

第一个单词首字母变大写:ucfirst()

?
1
2
3
4
5
6
7
8
<?php
$foo = 'hello world!';
$foo = ucfirst($foo);       // Hello world!
 
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar);       // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

第一个单词首字母变小写:lcfirst()

?
1
2
3
4
5
6
7
8
<?php
$foo = 'HelloWorld';
$foo = lcfirst($foo);       // helloWorld
 
$bar = 'HELLO WORLD!';
$bar = lcfirst($bar);       // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>

所有 字母变大写:strtoupper()

所有 字母变小写:strtolower()

以上这篇PHP字符串首字母大小写转换的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部