ucfirst – PHP String Functions

Syntax :

ucfirst ( string );

Description :

ucfirst() function will take string as input and converts its first letter of a string to uppercase letter, if that character is alphabetic. In general language, its name implies UC = Upper Case first letter in a string.


Parameter :

  • string – This is a Required parameter. This is a string on which function will be performed.

Output :

This will return a string with first letter converted to uppercase.


Related articles : ucwords()strtolower()strtoupper()lcfirst().


ucfirst() – PHP Functions Example 1 :
<?php
$strExample = "an example of a ucfirst() function.";
echo ucfirst($strExample);
?>

In above example ,We have a string ‘an example of a ucfirst() function’. Now this function will converts first letter in a string to Uppercase. See below is the output of above code.

An example of a ucfirst() function.

ucfirst() – PHP Functions Example 2 :
<?php
$strExample = "1. This is an example of ucfirst() function with numbers.";
echo ucfirst($strExample);
?>

In above example ,We have a string ‘1. This is an example of ucfirst() function with numbers.’. Now this function will converts every letter in a word to Uppercase, it will not do anything with numeric values. See below is the output of above code.

1. This is an example of ucfirst() function with numbers.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *