$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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.