Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • Last Modified:

Separating MYSQL variable into first name and last name

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
TLN_CANADA
Asked:
TLN_CANADA
  • 3
1 Solution
 
rossdalanginCommented:
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
 
TLN_CANADAAuthor Commented:
Sorry, I should have mentioned I'm using PHP, will this work?
0
 
Loganathan NatarajanLAMP DeveloperCommented:
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
 
rossdalanginCommented:
split and explode will do but using small letters

split(separator,string);
explode(separator,string);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now