在php中如果我们要把字符转换成大小写直接使用strtolower或者strtoupper即可,但是要首字母要转换大小写我们需要使用ucwords相关函数.
首字母变大写: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!Vevb.com
- ?>
第一个词首字母小写lcfirst(),代码如下:
- $foo = 'HelloWorld';
- $foo = lcfirst($foo); // helloWorld
- $bar = 'HELLO WORLD!';
新闻热点
疑难解答