php

How to capitalize the first letter of a string in PHP

In this tutorial, we are going to see how to capitalize the first letter of a string in PHP. You can use PHP’s ucfirst() function to change the first character of a string to upper case. You can also use the strtolower() function in combination with the ucfirst() function if you want only the first letter of the string to be capitalized and the rest of the string to be lowercase.
 

How to capitalize the first letter of a string in PHP
<?php
	$str1 = 'welcome to StackHowTo.';
	echo ucfirst($str1);
	echo "<br>";
	$str2 = 'welcome to StackHowTo.';
	echo ucfirst(strtolower($str2));
?>

Output:

Welcome to StackHowTo.
Welcome to stackhowto.

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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