In PHP, you can use the ucwords() function to convert the first letter of a word to uppercase; the function of this function is to convert the first letter of each word in the string to uppercase, and its syntax is "ucwords(str )", its parameter str represents the string to be converted. When using it, you only need to pass the string into str.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, you can use ucwords () function converts the first letter of a word to uppercase.
ucwords() function converts the first character of each word in a string to uppercase.
Note: This function is binary safe.
Syntax
ucwords(string)
Parameter string: required. Specifies the string to be converted.
Return value: Returns the converted string.
Code example:
<?php $foo = 'hello world!'; $foo = ucwords($foo); // Hello World! echo $foo."<br>"; $bar = 'HELLO WORLD!'; $bar = ucwords($bar); // HELLO WORLD! echo $bar."<br>"; $bar = ucwords(strtolower($bar)); // Hello World! echo $bar; ?>
Output:
Hello World! HELLO WORLD! Hello World!
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert the first letter of a word in a php statement to capitalized. For more information, please follow other related articles on the PHP Chinese website!