How to convert the first letter of php to uppercase: 1. Create a PHP sample file; 2. Use the "ucwords($foo)" method to convert the first letter of each word to uppercase; 3. Use "ucfirst ($foo);" method capitalizes the first letter of the first word.
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
How to convert the first letter of php to uppercase?
php method to convert the first letter from lowercase to uppercase
Convert the first letter of each word to uppercase: ucwords()
<?php $foo = 'hello world!'; $foo = ucwords($foo); // Hello World! $bar = 'HELLO WORLD!'; $bar = ucwords($bar); // HELLO WORLD! $bar = ucwords(strtolower($bar)); // Hello World! ?>
ucwords () function converts the first character of each word in a string to uppercase.
Change the first letter of the first word to uppercase: ucfirst()
<?php $foo = 'hello world!'; $foo = ucfirst($foo); // Hello world! $bar = 'HELLO WORLD!'; $bar = ucfirst($bar); // HELLO WORLD! $bar = ucfirst(strtolower($bar)); // Hello world! ?>
ucfirst() function converts the first character in the string to uppercase.
Recommended: "PHP Video Tutorial"
The above is the detailed content of How to convert the first letter of php to uppercase. For more information, please follow other related articles on the PHP Chinese website!