Basic Syntax</phpucfirst(string $string): string?>Example Usage<?php$string = "hello world";$capitalized = ucfirst($string);echo $capitalized; // Outputs: Hello world?>Important Notes About `ucfirst()` in PHP 8.21. Multibyte Support**: The standard `ucfirst()` doesn't handle multibyte characters properly. For UTF-8 strings, you should use `mb_ucfirst()`:<?phpfunction mb_ucfirst($string, $encoding = 'UTF-8') {$firstChar = mb_substr($string, 0, 1, $encoding);$then = mb_substr($string, 1, null, $encoding);return mb_strtoupper($firstChar, $encoding) . $then;}$string = "xample";echo mb_ucfirst($string); // Outputs: xample?>Remember that `ucfirst()` only capitalizes the very first character of the string. If you want to capitalize each word, you should use `ucwords()` instead.
ucfirst() Function in PHP 8.2,PHP 8.3, & 8.4
The `ucfirst()` function in PHP capitalizes the first character of a string. This function has been available in PHP for many versions and continues to work the same way in PHP 8.PHP 8.1,PHP 8.2,PHP 8.3,and PHP 8.4.