Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 95,475 PHP Programmers for FREE!. Ask your question and get quick answers from Dream.In.Code experts. There are 962 online right now! We're the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a PHP Expert

Register to Make This Box Go Away!


Separating VARCHARs or TEXTs

 
Reply to this topicStart new topic

Separating VARCHARs or TEXTs

Inertia
post 4 May, 2008 - 03:58 PM
Post #1


New D.I.C Head

*
Joined: 19 Apr, 2008
Posts: 12

What if I had a field in a sign-up form where the user was asked for their full name instead of their first and last name in separate fields.

How would I separate their first and last names using PHP?

So, for example, if I wanted to welcome users to a website using only their full name, the code would just use their first name, and not display their last name.

Also, how would I do something similar using TEXT, where a user inputs different words separated by commas (,). Then the code would be able to display each individual word pr phrase separately according to where the commas are?
User is offlineProfile CardPM

Go to the top of the page


spearfish
post 4 May, 2008 - 07:01 PM
Post #2


Monkey in Training

Group Icon
Joined: 10 Mar, 2008
Posts: 702



Dream Kudos: 200
My Contributions


Hmm.... try tokenizing.

php.net/strtok


--------------------
Like Sports? How about gambling? Bet with play money but cash out for real Washingtons!

IPB Image ST, -4/26/08

Freedom is never free: If you don't want to stand behind the troops; feel free to stand in front of them
User is offlineProfile CardPM

Go to the top of the page

joeyadms
post 4 May, 2008 - 11:11 PM
Post #3


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 141



Thanked 6 times

Dream Kudos: 600
My Contributions


Accepting input that way is very unpredictable. However as spearfish said you can tokenize, but the easiest way is just use explode().

CODE

Example.
$nameArray = explode(',',$fullName);
$firstName = $nameArray[0];
$lastName = $nameArray[1];

php.net/explode
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 7/5/08 03:36AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->