tags:

views:

99

answers:

3

As i have this:

$full_name = $data['full_name'];
list($firstname, $lastname) = explode(' ', $_POST['full_name']);

(after this comes a query where it inserts $lastname and $firstname)

Where should i use ucfirst() ?

Should i just make new variables again?

$newfirstname = ucfirst($firstname);
$newlastname = ucfirst($lastname);

or can i integrate ucfirst somehow somewhere in the code at top?

+5  A: 
list($firstName, $lastName) = array_map('ucfirst', explode(' ', $_POST['full_name']));

array_map will apply the function to all array elements.

nikic
+1  A: 

If they are proper names you could simply use the ucwords() function on the string.

http://www.php.net/manual/en/function.ucwords.php

Cups
A: 

I suggest using something like

$full_name = ucwords(strtolower($_POST['full_name']));

your approach

list($firstname, $lastname) = explode(' ', $_POST['full_name']);

doesn't work for names containing more than one space.

aeon