php字符串首字母转换大小写实例
在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!phprm.com ?>
第一个词首字母小写lcfirst(),代码如下:
<?php $foo = 'HelloWorld'; $foo = lcfirst($foo); // helloWorld $bar = 'HELLO WORLD!'; ?>
教程网址:http://www.phprm.com/develop/fs3634.html
欢迎收藏∩_∩但请保留本文链接。