PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I make the first letter of a string uppercase?


If this question has been keeping you awake, then you will sleep soundly after reading this.

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 convert relevant characters in a string to HTML entities?

What is the difference between join and implode in PHP?

How do I make the first letter of each word upper case?

How do I make the contents of a string upper case?

How do I add commas easily to a string of numbers?



Custom Search