Home > Article > Backend Development > What is the function in php to convert the first letter to capital?
In PHP, the function that converts the first letter to uppercase is ucfirst(). The function of this function is to convert the first letter of a string to uppercase. The syntax is "ucfirst(string)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In php, I want to convert To capitalize the first letter, you can use the ucfirst() function. (On the contrary, if you want to convert the first letter to lowercase, you can use the lcfirst() function.)
ucfirst function can convert the first letter of a string to uppercase. The syntax format is as follows:
ucfirst($string)
Among them, $string is the string that needs to be converted.
Example:
<?php $str = 'hello world!'; $str = ucfirst($str); echo $str.'<br>'; $str2 = 'HELLO WORLD!'; $str2 = ucfirst(strtolower($str2)); echo $str2; ?>
Output result:
Hello world! Hello world!
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the function in php to convert the first letter to capital?. For more information, please follow other related articles on the PHP Chinese website!