How do I make the first letter of a string uppercase?
The answer to your enquiry is the function called ucfirst() which doesn't mean you were the first person to see, but rather UpperCaseFirst.
Like this:
<?php
$unexpected = " how are you today?";
echo ucfirst($unexpected);
// how are you today?
?>
Note that you didn't get the expected result here, and that's because the first character is actually a space.
The lesson is, when using this function it is best to always pass the string through trim first to get rid of any leading space, so you always get the expected results:
<?php
$expected = " how are you today?";
echo ucfirst(trim($expected));
//How are you today?
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More strings PHP Questions
How do I find the ASCII value of a string character?How do I find the length of a string in PHP?
How can I remove trailing space from a string?
How do I find the position of a letter in a string in PHP?
How do I break email address into username and hostname?
