How to capitalize the first letter of a String in PHP


In PHP, we can use the inbuild ucfirst(string $string) function to convert the first character of a string to uppercase. ucfirst(string $string) function is available from PHP 4+ versions.

Similar Post: How to convert the first letter of a String to lowercase in PHP

<?php

	$str1 = 'atul rai';
	$str1 = ucfirst($str1);      
	echo $str1;                 // Atul rai

	$str2 = 'ATUL RAI';
	$str2 = ucfirst($str2);            
	echo $str2;                 // ATUL RAI
	
	$str3 = '#atul rai';
	$str3 = ucfirst($str3);             
	echo $str3;                 // #atul rai
	
?>

References

  1. ucfirst

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.