Q:

How to convert the first letter of a string to uppercase in PHP

0

How to convert the first letter of a string to uppercase in PHP

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the PHP ucfirst() function

You can use the PHP ucfirst() function to change the first character of a string to uppercase (i.e. capital). Alternatively, you can use the strtolower() function in combination with the ucfirst() function, if you want to make only first letter of the string to uppercase and rest of the string to lowercase. Let's check out an example to understand how it works:

<?php
$str1 = 'the color of the sky is blue.';
echo ucfirst($str1);
echo "<br>";
$str2 = 'the Color of the Sky is Blue.';
echo ucfirst(strtolower($str2));
?>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP  and MySQL Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to convert special HTML entities back to chara... >>
<< How to convert a string to uppercase in PHP...