jeff5656 Posted January 26, 2011 Share Posted January 26, 2011 I have a field called full_name and it has John Smith as a value. I want to take John and put it to the first_name field and Smith to the last_name field. How do I do this, knowing that the first and last name are separateed by a space? Here's a query I did that does the same thing when they are separated by a COMMA, but I am not familiar with regular expressions enough to modify it to include space instead :-) $newlastname = $row['full_name']; if (preg_match('/^[^,]+(?=,)/', $row['full_name'], $match)) { $newlastname = $match[0]; } list($newlastname,$newfirstname) = explode(',',$row['full_name']); Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 26, 2011 Share Posted January 26, 2011 $oldname = $row['full_name']; $temp_array = explode(" ", $oldname); $firstname = $temp_array[0]; $lastname = $temp_array[1]; Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted January 26, 2011 Share Posted January 26, 2011 Only because it's shorter list($firstname, $lastname) = explode(' ', $row['full_name']); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.