ucfirst() Make a string's first character uppercase
This tutorial will teach you how to uppercase the first character of a string.
The ucfirst() function capitalizes the first character of a string (if that character is alphabetic) which is good for sentences.
ucfirst() prototype
This means thatstring ucfirst ( string $str )
ucfirst() accepts string and returns a manipulated string (uppercased the first character).
We could rewrite the above function definition in an easy to understandable way:
| Function Part | Description |
|---|---|
| string | Type of value this function returns, which is a string |
| ucfirst | The function name |
| string | Parameter type, this function accepts only string data type |
| $str | Parameter name, a variable that holds the data |
Syntax
ucfirst($str)
Return Value
ucfirst() function returns string, with capitalized the first character if that character is alphabetic.
Examples
Example 1
<?php
$str = 'i am php string';
//uppercase first character of string
$UpperFirst = ucfirst($str);
echo $UpperFirst;
?>
The above code prints I am php string on browser screen.
