View Full Version : Splitting an inconsistently sized item.
OK so here is my code for splitting a form submitter's name into its constiuuent parts of firstnanme, middlename and lastname.
###########################################
#split $sendername into it components
###########################################
chomp ($sendername);
($firstname,$lastname) = split(/ /,$sendername);
#That splits to give vars like these?
#$firstname = First Name
#$middlename = Middle Name
#$lastname = Last Name
#############################
This works if I assume that there will always only be two names entered. However in some people have three name such as Denise Van Outen ( can't think of why I thought of her name :) ).
So I need to make this work where some senders will use thre anmes and others, two.
Bazz
mlseim
02-21-2005, 04:02 PM
Bazz .... it's going to be tough to do.
All I can think of is testing all "split surnames" that you can think of.
Not a very good answer, but it might work.
Here's a list of surname prefixes:
http://www.library.yale.edu/cataloging/music/entryele.htm
===========================================================
###########################################
#split $sendername into it components
###########################################
$sendername="Denise Von Outen";
chomp ($sendername);
($firstname,$name1,$name2) = split(/ /,$sendername);
$middlename=$name1;
$lastname=$name2;
if(($name1 eq "Van")||($name1 eq "Von")||($name1 eq "Le"))
{$lastname = "$name1 $name2"; $middlename="";}
unless($name2){$lastname=$name1; $middlename="";}
print "First: $firstname<br>";
print "Middle: $middlename<br>";
print "Last: $lastname<br>";
#############################
Hmmm.
I think for now, I'll just run with it as it is so I shall just use the first name. When I have more time, I'll explore this further.
Thanks Mlseim.
Bazz
requestcode
02-21-2005, 07:33 PM
Can you change the form to have separate fields for each part of the name?
requestcode Thanks!! :thumbsup:
Now why didn't I think of that. :eek:
form being changed as I write :)
Bazz
mlseim
02-21-2005, 09:20 PM
requestcode ...
Bazz is always looking for "other ways" to do things ... ;)
Gotta give him what he wants .... :thumbsup:
... and besides that, I didn't see it either :o
andyede
02-22-2005, 09:18 AM
I did but i got here too late to prove it! :D
Hey, (and plz don't think I got the humpy head on), I ain't looking just to do things differently. I am trying to find a better way. ;)
If I am a pain, plz don't be backward in coming forwards - just say. :cool:
Now back to the subject and I'm nearly there........ YAY!!!! x 100
Just have to add a bit if input hidden and then for that over-used 'big browser' sort the css and I can move to the next stage. I think I need a bit of a break first so I shall work at something else like re-designing the pages. ;)
bazz
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.