Bootstrap FreeKB - PHP - Update first character to upper using ucfirst
PHP - Update first character to upper using ucfirst

Updated:   |  PHP articles

ucfirst can be used to update a string so that the first character is upper case. For example, let's say you have a variable that contains the text hello world.

$string = "hello world";

 

In this example, the first character in $string will be updated to upper.

$string = ucfirst($string);

 

Now, when you echo $string. . .

echo $string;

 

. . . the following will be displayed.

Hello world

 

Optionally, you could also use strtolower to first update the string to all lower case to guarantee that only the first character is upper.

$string = strtolower(ucfirst($string));

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter dc2ff6 in the box below so that we can be sure you are a human.