PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Jul 14, 2020 4:12 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Aug 11, 2014 9:40 pm 
Offline
Forum Contributor

Joined: Mon Aug 11, 2014 11:18 am
Posts: 179
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


Top
 Profile  
 
PostPosted: Mon Aug 11, 2014 10:08 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6425
Location: Montreal, Canada


Top
 Profile  
 
PostPosted: Mon Aug 11, 2014 10:41 pm 
Offline
Forum Contributor

Joined: Mon Aug 11, 2014 11:18 am
Posts: 179
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

Syntax: [ Download ] [ Hide ]
//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


Top
 Profile  
 
PostPosted: Mon Aug 11, 2014 11:38 pm 
Offline
Forum Contributor

Joined: Mon Aug 11, 2014 11:18 am
Posts: 179
i got it.

thanks anyway


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group