PHP头条
热点:

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!
?>

第一个词首字母小写lcfirst()

 代码如下 复制代码

<?php
$foo = 'HelloWorld';
$foo = lcfirst($foo); // helloWorld

$bar = 'HELLO WORLD!';

www.phpzy.comtrue/php/31753.htmlTechArticlephp字符串首字母转换大小写实例 在php中如果我们要把字符转换成大小写直接使用strtolower或者strtoupper即可,但是要首字母要转换大小写我们需要使用ucwords相关函数 首字母变大写:ucwo...

相关文章

PHP之友评论

今天推荐