PHP将字符串首字母大小写转换
每个单词的首字母转换为大写:ucwords()
- 3
|
- $foo
- = ucwords(
- $foo
- );
- // Hello World!
|
- 6
|
- $bar
- = ucwords(
- $bar
- );
- // HELLO WORLD!
|
- 7
|
- $bar
- = ucwords(
- strtolower
- (
- $bar
- ));
- // Hello World!
|
第一个单词首字母变大写:ucfirst()
- 3
|
- $foo
- = ucfirst(
- $foo
- );
- // Hello world!
|
- 6
|
- $bar
- = ucfirst(
- $bar
- );
- // HELLO WORLD!
|
- 7
|
- $bar
- = ucfirst(
- strtolower
- (
- $bar
- ));
- // Hello world!
|
第一个单词首字母变小写:lcfirst()
- 3
|
- $foo
- = lcfirst(
- $foo
- );
- // helloWorld
|
- 6
|
- $bar
- = lcfirst(
- $bar
- );
- // hELLO WORLD!
|
- 7
|
- $bar
- = lcfirst(
- strtoupper
- (
- $bar
- ));
- // hELLO WORLD!
|
所有 字母变大写:strtoupper()
所有 字母变小写:strtolower()
来源: http://www.phpxs.com/code/1003523/