To convert the first letter of a word to uppercase in PHP, you can use the ucfirst()
function. This function converts the first character of a string to uppercase, and returns the modified string.
For example:
$string = 'hello';
$string = ucfirst($string);
// $string will be equal to 'Hello'
You can also use the mb_strtoupper()
function to convert the first character of a multibyte string to uppercase. This function requires the mbstring
extension to be enabled in your PHP configuration.
For example:
$string = 'héllo';
$string = mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);
// $string will be equal to 'Héllo'