hello
can somebody please help me
I have 2 fields $firstname and $lastname
I want to make a $fullname which is basically $firstname + $lastname but i want the format of the name to be like this
John Doe
and if the last name has a ' I want the letter after the ' to capitalize also
John D'Angelo
thank you
Make First letter uppercase and the rest lowercase
Moderator: General Moderators
Re: Make First letter uppercase and the rest lowercase
I found this code online can somebody please edit it so it will work with my variables please.
my name variable is $first_last_name
if possible i want to create a variable $first_last_name_edited to be the fixed name
thank you very much
my name variable is $first_last_name
if possible i want to create a variable $first_last_name_edited to be the fixed name
Code: Select all
//FUNCTION
function ucname($string) {
$string =ucwords(strtolower($string));
foreach (array('-', '\'') as $delimiter) {
if (strpos($string, $delimiter)!==false) {
$string =implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
}
}
return $string;
}
//TEST
$names =array(
'JEAN-LUC PICARD',
'MILES O\'BRIEN',
'WILLIAM RIKER',
'geordi la forge',
'bEvErly CRuSHeR'
);
foreach ($names as $name) { print ucname("{$name}\n"); }
thank you very much
Re: Make First letter uppercase and the rest lowercase
i got it.
thanks anyway
thanks anyway