PHP Function Reference

PHP ucfirst() Function



The PHP ucfirst() function returns the string with first character of the specified string in the uppercase. Any symbol, space, special character or number in the string is ignored while applying this function. Only Alphabets are converted.

Note: Alphabet is determined by the current locale. For instance, in the default "C" locale characters such as umlaut-a (ä) will not be converted.

Syntax

ucfirst(string)

Parameters

string Required. Specify the string to convert.

Return Value

Returns the string with first character of the specified string in uppercase.

Example:

The example below shows the usage of ucfirst() function.

<?php
$str1 = "hello world!";
$ucf_str1 = ucfirst($str1);
echo $ucf_str1."\n";

$str2 = "HELLO WORLD!";
echo ucfirst($str2)."\n";
echo ucfirst(strtolower($str2))."\n";
?>

The output of the above code will be:

Hello world!
HELLO WORLD!
Hello world!

❮ PHP String Reference