disecting a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

disecting a string

Post by aceconcepts »

Hi,

I have a contact form with a name field.

In this name field the user will enter there full name i.e. "Bill Smith"

My question is: how can I split up this string so that I can insert both the first and last name into seperate fields in a database?

Thanks.
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Code: Select all

$names = explode(" ", $_POST['name']);
$first_name = $names[0];
$last_name = $names[1];
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Thanks for the response.

Cheers
Post Reply