PHP | ucfirst() Function
The ucfirst() function is a built-in function in PHP which takes a string as an argument and returns the string with the first character in Upper Case and all other characters remain unchanged.
Syntax:
ucfirst($string)
Parameter: The function accepts only one parameter $string which is mandatory. This parameter represents the string whose first character will be changed to uppercase.
Return Value: The function returns the same string only by changing the first character to upper case of the passed argument $string.
Examples:
Input : "geeks for geeks" Output : Geeks for geeks Input : "Chetna Agarwal" Output : Chetna Agarwal
Below programs illustrate the ucfirst() function in PHP:
Program 1: The program below demonstrates the use of ucfirst() function.
<?php // PHP program that demonstrates the // use of ucfirst() function $str = "geeks for geeks"; // converts the first case to upper case // and prints the string echo(ucfirst($str)); ?> |
Output:
Geeks for geeks
Program 2: The program below demonstrates the use of ucfirst() function when the starting character is in upper-case.
<?php // PHP program that demonstrates the // use of ucfirst() function when // the first case is already in uppercase $str = "Chetna Agarwal"; // already the first character is in upper case // so prints the same string only echo(ucfirst($str)); ?> |
Output:
Chetna Agarwal
Reference:
http://php.net/manual/en/function.ucfirst.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- p5.js | sq() function
- D3.js | d3.map.set() Function
- p5.js | abs() function
- p5.js | second() function
- p5.js | nf() Function
- D3.js | d3.map.get() Function
- p5.js | day() function
- p5.js | nfp() Function
- p5.js | nfs() Function
- p5.js | pow() function
- p5.js | nfc() function
- D3.js | d3.lab() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



