In php, if we want to convert characters to uppercase or lowercase, we can just use strtolower or strtoupper, but to convert the first letter to uppercase, we need to use ucwords related functions
Change the first letter to uppercase: ucwords()
The code is as follows
代码如下 |
复制代码 |
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!
$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>
|
|
Copy code
|
代码如下 |
复制代码 |
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>
|
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!
$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>
代码如下 |
复制代码 |
$foo = 'HelloWorld';
$foo = lcfirst($foo); // helloWorld
$bar = 'HELLO WORLD!';
|
|
The first letter of the first word is capitalized: ucfirst()
The code is as follows
Copy code
|
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>
The first letter of the first word is lowercase lcfirst()
The code is as follows
|
Copy code
|
$foo = 'HelloWorld';
$foo = lcfirst($foo); // helloWorld$bar = 'HELLO WORLD!';
http://www.bkjia.com/PHPjc/632754.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632754.htmlTechArticleIn php, if we want to convert characters to upper and lower case, we can just use strtolower or strtoupper, but the first letter is required To convert uppercase and lowercase we need to use ucwords related functions to change the first letter...
|
|
|