ucfirst() Make a string's first character uppercase

This tutorial will teach you how to uppercase the first character of a string.

The ucfirst() function capitalizes the first character of a string (if that character is alphabetic) which is good for sentences.







ucfirst() prototype

string ucfirst ( string $str )
This means that ucfirst() accepts string and returns a manipulated string (uppercased the first character). We could rewrite the above function definition in an easy to understandable way:
Explanation of ucfirst() function definition
Function PartDescription
stringType of value this function returns, which is a string
ucfirstThe function name
stringParameter type, this function accepts only string data type
$strParameter name, a variable that holds the data

Syntax

ucfirst($str)

Return Value

ucfirst() function returns string, with capitalized the first character if that character is alphabetic.

Examples

Example 1

<?php
    $str 
'i am php string';
    
//uppercase first character of string
    
$UpperFirst ucfirst($str);
    echo 
$UpperFirst;
?>

The above code prints I am php string on browser screen.

Contents and Related Tutorials

  1. Make string first's character uppercase
  2. Make string first's character lowercase
  3. Make a string lowercase
  4. Make a string uppercase
  5. Uppercase first character of each word in a string