Solved

Separating MYSQL variable into first name and last name

Posted on 2013-01-21
5
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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.

739 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