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! ?>
第一个单词首字母变大写:ucfirst()
<?php $foo = 'hello world!'; $foo = ucfirst($foo); // Hello world! $bar = 'HELLO WORLD!'; $bar = ucfirst($bar); // HELLO WORLD! $bar = ucfirst(strtolower($bar)); // Hello world! ?>
第一个单词首字母变小写:lcfirst()
<?php $foo = 'HelloWorld'; $foo = lcfirst($foo); // helloWorld $bar = 'HELLO WORLD!'; $bar = lcfirst($bar); // hELLO WORLD! $bar = lcfirst(strtoupper($bar)); // hELLO WORLD! ?>
所有 字母变大写:strtoupper()
所有 字母变小写:strtolower()
相关推荐
WasteLand 2020-08-15
solarLan 2019-06-21
zzzzzdddddxxxxx 2016-11-26
Justhavefun 2020-09-25
NVEFLY 2020-04-19
Leonwey 2020-04-11
坚持是一种品质 2020-01-04
cjcsdn 2019-11-02
wordmhg 2019-10-24
Go贝壳 2015-06-14
zzhuagn 2015-07-19
AIApple 2016-09-01
Kwong 2019-07-01
wayne0 2019-06-29
琪凡睿 2016-07-18
wolaoreme 2019-06-27
zwblcz 2019-06-26