Solved

Separating MYSQL variable into first name and last name

Posted on 2013-01-21
5
462 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
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.

705 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

13 Experts available now in Live!

Get 1:1 Help Now