Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display the first letter as uppercase?

Tags:

php

mysql

I have fname and lname in my database, and a name could be stored as JOHN DOE or john DOE or JoHN dOE, but ultimately I want to display it as John Doe

fname being John and lname being Doe

like image 908
Brad Avatar asked Oct 08 '08 13:10

Brad


3 Answers

Be aware that there are other capitalisation formats, such as John McDoe, John D'Oe, John de O, and John van den Doe.

like image 185
harriyott Avatar answered Oct 21 '22 04:10

harriyott


seeing it is tagged PHP:
either

string ucfirst ( string $str );

to uppercase first letter of the first word

or

string ucwords ( string $str );

to uppercase the first letter of every word

you might want to use those in combination with

string strtolower ( string $str );

to normalize all names to lower case first.

like image 40
Jacco Avatar answered Oct 21 '22 06:10

Jacco


I'm not sure where and how you want to display it, but if it's on a web-page you might try simply altering the display using CSS. Try adding:

text-transform:capitalize;

to the relevant rule, like this:

.name { text-transform:capitalize;}

if you put the name in a div or span with class="name". Of course, this will not in any way alter the database entry, but I wasn't clear which was preferable.

like image 22
Dave Rutledge Avatar answered Oct 21 '22 06:10

Dave Rutledge