Function to convert the first letter from lowercase to uppercase in php: 1. ucfirst() function, which can convert the first letter of a string to uppercase, the syntax is "ucfirst($str)"; 2. ucwords() function, You can convert the first letter of each word in a string to uppercase with the syntax "ucwords($str)".
The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer
The functions to convert the first letter from lower case to upper case in php are Two types:
ucfirst() function, which can convert the first letter of the string into uppercase
ucwords() function, which can convert the characters Convert the first letter of each word in the string to uppercase
1. ucfirst() function
ucfirst() function converts the first letter of each word in the string to uppercase The first character is converted to uppercase.
Example:
<?php echo ucfirst("hello world!"); ?>
2. ucwords() function
ucwords() function The first character of each word in the string is converted to uppercase.
Grammar:
ucwords($string [, $delimiters = "\t\r\n\f\v" ])
Among them, $string is the string that needs to be converted; $delimiters is an optional parameter, used to represent word delimiters. The default is space and tab. character, line feed character, carriage return character, horizontal line and vertical bar.
Example:
<?php $foo = 'hello world!'; $foo = ucwords($foo); // Hello World! echo $foo."<br>"; $foo = 'hello|world!'; $bar = ucwords($foo); // Hello|world! echo $bar."<br>"; $baz = ucwords($foo,"|"); // Hello|World! echo $baz."<br>"; ?>
Output:
Hello World! 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 from lower case to upper case?. For more information, please follow other related articles on the PHP Chinese website!