Solved

Separating MYSQL variable into first name and last name

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

740 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