$output=ucfirst($input_str);
| Parameter | DESCRIPTION |
|---|---|
| $input_str | Required : Input string |
$str="welcome to plus2net.com";
$str=ucfirst($str);
echo $str;
The output is here
Welcome To plus2net.com
Use ucfirst() with trim() to capitalize the first character of a string that may contain leading whitespace.
$str = " php tutorial";
$str = ucfirst(trim($str));
echo $str; // Outputs: Php tutorial
Since ucfirst() doesn’t handle multibyte characters, for non-ASCII strings, use *mb_ucfirst()*:
function mb_ucfirst($str) {
return mb_strtoupper(mb_substr($str, 0, 1)) . mb_substr($str, 1);
}
echo mb_ucfirst("élève"); // Outputs: Élève
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.