PHP新特性 第9.4章 字符串-首字母大小写 PHP新特性 第9.4章 字符串-首字母大小写

2023-06-16

①、ucwords:每个单词的首字母转换为大写

$foo = 'hello world!';
$foo = ucwords($foo);             // Hello World!
 
$bar = 'HELLO WORLD!';
$bar = ucwords($bar);             // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!

②、ucfirst:第一个单词首字母变大写

$foo = 'hello world!';
$foo = ucfirst($foo);             // Hello world!
 
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!

③、lcfirst:第一个单词首字母变小写

$foo = 'HelloWorld';
$foo = lcfirst($foo);             // helloWorld
 
$bar = 'HELLO WORLD!';
$bar = lcfirst($bar);             // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!

④、strtoupper:所有 字母变大写

⑤、strtolower:所有 字母变小写

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开微信扫一扫,即可进行扫码打赏哦

阅读 243