Solved

Separating MYSQL variable into first name and last name

Posted on 2013-01-21
5
463 Views
Last Modified: 2013-01-21
Hi all,

I have a user's full name in a variable called $fullname

Is there an easy way to take the first word of this variable and make it into a different variable as I only want the user's first name.

Thanks,

D
0
Comment
Question by:TLN_CANADA
  • 3
5 Comments
 
LVL 2

Expert Comment

by:rossdalangin
ID: 38803947
if the separator is a space then:

Dim arrSplit() as String
  arrSplit() = Split($fullname, " ")
  firstname=arrSplit(0)


or

Dim firstname as String

If InStr(1, fullname, " ") > 0 Then
         firstname = LTrim(fullname, 1, InStr(1, fullname, " "))
End If
0
 

Author Comment

by:TLN_CANADA
ID: 38803952
Sorry, I should have mentioned I'm using PHP, will this work?
0
 
LVL 36

Accepted Solution

by:
Loganathan Natarajan earned 500 total points
ID: 38804055
if you have space in your name as separator, this will work

<?php
// Example 1
$name = "Loganathan Natarajan";

$pieces = explode(" ", $name );

echo $pieces[0]; // Loganathan

echo $pieces[1]; // Natarajan

?>
0
 
LVL 2

Expert Comment

by:rossdalangin
ID: 38804112
split and explode will do but using small letters

split(separator,string);
explode(separator,string);
0
 
LVL 2

Expert Comment

by:rossdalangin
ID: 38804118
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now