Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.php

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2012, 06:47 PM
Kevin Davis
Guest
 
Posts: n/a
Default PHP Concatenate

Hi there,

Here is what I'm trying to do.. I'm trying to merge the first and last name(that I can do) into an email address. But what I'm trying to do is to drop the middle initial. If the entry was from a form, I would have no problem, but the data will be uploaded from a different source, how would I go about dropping the middle initial?

Would I use regex??

Thank you,
Kevin
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 05-21-2012, 07:17 PM
bill
Guest
 
Posts: n/a
Default Re: PHP Concatenate

On 5/21/2012 2:47 PM, Kevin Davis wrote:
> Hi there,
>
> Here is what I'm trying to do.. I'm trying to merge the first and last name (that I can do) into an email address. But what I'm trying to do is to drop the middle initial. If the entry was from a form, I would have no problem, but the data will be uploaded from a different source, how would I go about dropping the middle initial?
>
> Would I use regex??
>
> Thank you,
> Kevin


I really hate to ask these because I fear the answers:

will there always be a middle initial ?

Will there be any first or last names with embedded spaces ? (eg
Jean Paul Aloysius Smith ?

bill
Reply With Quote
  #3 (permalink)  
Old 05-21-2012, 07:19 PM
Luuk
Guest
 
Posts: n/a
Default Re: PHP Concatenate

On 21-05-2012 20:47, Kevin Davis wrote:
> Hi there,
>
> Here is what I'm trying to do.. I'm trying to merge the first and last name (that I can do) into an email address. But what I'm trying to do is to drop the middle initial. If the entry was from a form, I would have no problem, but the data will be uploaded from a different source, how would I go about dropping the middle initial?
>
> Would I use regex??
>
> Thank you,
> Kevin


$name="Kevin R. Davis";
$a=split(" ",$name);
print $a[0]." ".$a[count($a)-1];

It should print:
Kevin Davis
Reply With Quote
  #4 (permalink)  
Old 05-22-2012, 11:34 AM
Captain Paralytic
Guest
 
Posts: n/a
Default Re: PHP Concatenate

On May 21, 7:47*pm, Kevin Davis <kevindavis...@gmail.com> wrote:
> Hi there,
>
> Here is what I'm trying to do.. I'm trying to merge the first and last name (that I can do) into an email address. But what I'm trying to do is to drop the middle initial. If the entry was from a form, I would have no problem, but the data will be uploaded from a different source, how would I go about dropping the middle initial?
>
> Would I use regex??


You might if you wanted and if the full problem had a decent regex
solution to match it. However as Bill and Luuk have shown, you have
not given enough data in order for us to evaluate it.
Reply With Quote
  #5 (permalink)  
Old 05-22-2012, 12:21 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: PHP Concatenate

On 5/21/2012 3:19 PM, Luuk wrote:
> On 21-05-2012 20:47, Kevin Davis wrote:
>> Hi there,
>>
>> Here is what I'm trying to do.. I'm trying to merge the first and last name (that I can do) into an email address. But what I'm trying to do is to drop the middle initial. If the entry was from a form, I would have no problem, but the data will be uploaded from a different source, how would I go about dropping the middle initial?
>>
>> Would I use regex??
>>
>> Thank you,
>> Kevin

>
> $name="Kevin R. Davis";
> $a=split(" ",$name);
> print $a[0]." ".$a[count($a)-1];
>
> It should print:
> Kevin Davis


What about "John Smith Jr"?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #6 (permalink)  
Old 05-22-2012, 01:42 PM
Peter H. Coffin
Guest
 
Posts: n/a
Default Re: PHP Concatenate

On Tue, 22 May 2012 08:21:27 -0400, Jerry Stuckle wrote:
> On 5/21/2012 3:19 PM, Luuk wrote:
>> On 21-05-2012 20:47, Kevin Davis wrote:
>>> Hi there,
>>>
>>> Here is what I'm trying to do.. I'm trying to merge the first and
>>> last name (that I can do) into an email address. But what I'm
>>> trying to do is to drop the middle initial. If the entry was from a
>>> form, I would have no problem, but the data will be uploaded from a
>>> different source, how would I go about dropping the middle initial?
>>>
>>> Would I use regex??
>>>
>>> Thank you,
>>> Kevin

>>
>> $name="Kevin R. Davis";
>> $a=split(" ",$name);
>> print $a[0]." ".$a[count($a)-1];
>>
>> It should print:
>> Kevin Davis

>
> What about "John Smith Jr"?


Or "Carlos Salinas de Gortari"?

To cut to the important point, "dropping middle initial" is a kind
of simple problem surround by worm-cans with very weak lids. Pretty
much the least damaging thing you can do is drop punctuation and any
single-letter (not single character, just Latin letter) words, using two
passes with regexp processing. Usually if someone has put something into
a field on form asking for their name, whatever they've put there is
important to them.

You'll still piss off will.i.am of The Black-Eyed Peas even with that
simple step.

--
Never correct Halloween decorations where the guidance counselor can see.
It makes for very tedious conversations later.
Reply With Quote
  #7 (permalink)  
Old 05-22-2012, 02:21 PM
Paul Herber
Guest
 
Posts: n/a
Default Re: PHP Concatenate

On Tue, 22 May 2012 08:42:54 -0500, "Peter H. Coffin" <hellsop@ninehells.com> wrote:

>On Tue, 22 May 2012 08:21:27 -0400, Jerry Stuckle wrote:
>> On 5/21/2012 3:19 PM, Luuk wrote:
>>> On 21-05-2012 20:47, Kevin Davis wrote:
>>>> Hi there,
>>>>
>>>> Here is what I'm trying to do.. I'm trying to merge the first and
>>>> last name (that I can do) into an email address. But what I'm
>>>> trying to do is to drop the middle initial. If the entry was from a
>>>> form, I would have no problem, but the data will be uploaded from a
>>>> different source, how would I go about dropping the middle initial?
>>>>
>>>> Would I use regex??
>>>>
>>>> Thank you,
>>>> Kevin
>>>
>>> $name="Kevin R. Davis";
>>> $a=split(" ",$name);
>>> print $a[0]." ".$a[count($a)-1];
>>>
>>> It should print:
>>> Kevin Davis

>>
>> What about "John Smith Jr"?

>
>Or "Carlos Salinas de Gortari"?
>
>To cut to the important point, "dropping middle initial" is a kind
>of simple problem surround by worm-cans with very weak lids. Pretty
>much the least damaging thing you can do is drop punctuation and any
>single-letter (not single character, just Latin letter) words, using two
>passes with regexp processing. Usually if someone has put something into
>a field on form asking for their name, whatever they've put there is
>important to them.
>
>You'll still piss off will.i.am of The Black-Eyed Peas even with that
>simple step.


and anyone with the surname De'Ath.



--
Regards, Paul Herber, Sandrila Ltd.
http://www.sandrila.co.uk/
Reply With Quote
  #8 (permalink)  
Old 05-22-2012, 03:37 PM
The Natural Philosopher
Guest
 
Posts: n/a
Default Re: PHP Concatenate

Paul Herber wrote:
> On Tue, 22 May 2012 08:42:54 -0500, "Peter H. Coffin" <hellsop@ninehells.com> wrote:
>
>> On Tue, 22 May 2012 08:21:27 -0400, Jerry Stuckle wrote:
>>> On 5/21/2012 3:19 PM, Luuk wrote:
>>>> On 21-05-2012 20:47, Kevin Davis wrote:
>>>>> Hi there,
>>>>>
>>>>> Here is what I'm trying to do.. I'm trying to merge the first and
>>>>> last name (that I can do) into an email address. But what I'm
>>>>> trying to do is to drop the middle initial. If the entry was from a
>>>>> form, I would have no problem, but the data will be uploaded from a
>>>>> different source, how would I go about dropping the middle initial?
>>>>>
>>>>> Would I use regex??
>>>>>
>>>>> Thank you,
>>>>> Kevin
>>>> $name="Kevin R. Davis";
>>>> $a=split(" ",$name);
>>>> print $a[0]." ".$a[count($a)-1];
>>>>
>>>> It should print:
>>>> Kevin Davis
>>> What about "John Smith Jr"?

>> Or "Carlos Salinas de Gortari"?
>>
>> To cut to the important point, "dropping middle initial" is a kind
>> of simple problem surround by worm-cans with very weak lids. Pretty
>> much the least damaging thing you can do is drop punctuation and any
>> single-letter (not single character, just Latin letter) words, using two
>> passes with regexp processing. Usually if someone has put something into
>> a field on form asking for their name, whatever they've put there is
>> important to them.
>>
>> You'll still piss off will.i.am of The Black-Eyed Peas even with that
>> simple step.

>
> and anyone with the surname De'Ath.
>
>

He assisted with my late mothers will, did Mr De'Ath. Genuinely!

>



--
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.
Reply With Quote
  #9 (permalink)  
Old 05-22-2012, 06:18 PM
Luuk
Guest
 
Posts: n/a
Default Re: PHP Concatenate

On 22-05-2012 16:21, Paul Herber wrote:
> On Tue, 22 May 2012 08:42:54 -0500, "Peter H. Coffin" <hellsop@ninehells.com> wrote:
>
>> On Tue, 22 May 2012 08:21:27 -0400, Jerry Stuckle wrote:
>>> On 5/21/2012 3:19 PM, Luuk wrote:
>>>> On 21-05-2012 20:47, Kevin Davis wrote:
>>>>> Hi there,
>>>>>
>>>>> Here is what I'm trying to do.. I'm trying to merge the first and
>>>>> last name (that I can do) into an email address. But what I'm
>>>>> trying to do is to drop the middle initial. If the entry was from a
>>>>> form, I would have no problem, but the data will be uploaded from a
>>>>> different source, how would I go about dropping the middle initial?
>>>>>
>>>>> Would I use regex??
>>>>>
>>>>> Thank you,
>>>>> Kevin
>>>>
>>>> $name="Kevin R. Davis";
>>>> $a=split(" ",$name);
>>>> print $a[0]." ".$a[count($a)-1];
>>>>
>>>> It should print:
>>>> Kevin Davis
>>>
>>> What about "John Smith Jr"?

>>
>> Or "Carlos Salinas de Gortari"?
>>
>> To cut to the important point, "dropping middle initial" is a kind
>> of simple problem surround by worm-cans with very weak lids. Pretty
>> much the least damaging thing you can do is drop punctuation and any
>> single-letter (not single character, just Latin letter) words, using two
>> passes with regexp processing. Usually if someone has put something into
>> a field on form asking for their name, whatever they've put there is
>> important to them.
>>
>> You'll still piss off will.i.am of The Black-Eyed Peas even with that
>> simple step.

>
> and anyone with the surname De'Ath.
>
>
>


~/tmp> cat surname.php
<?php
$name="Kevin R. De'Ath";
$a=split(" ",$name);
print $a[0]." ".$a[count($a)-1];
?>

~/tmp> php surname.php
Kevin De'Ath
~/tmp>

But, of course, this method is not perfect and/or complete.

But where is the OP.....?

Why does not he/she give a clue about what is expected?
Reply With Quote
  #10 (permalink)  
Old 05-22-2012, 06:30 PM
Luuk
Guest
 
Posts: n/a
Default Re: PHP Concatenate

On 22-05-2012 16:21, Paul Herber wrote:
> On Tue, 22 May 2012 08:42:54 -0500, "Peter H. Coffin" <hellsop@ninehells.com> wrote:
>
>> On Tue, 22 May 2012 08:21:27 -0400, Jerry Stuckle wrote:
>>> On 5/21/2012 3:19 PM, Luuk wrote:
>>>> On 21-05-2012 20:47, Kevin Davis wrote:
>>>>> Hi there,
>>>>>
>>>>> Here is what I'm trying to do.. I'm trying to merge the first and
>>>>> last name (that I can do) into an email address. But what I'm
>>>>> trying to do is to drop the middle initial. If the entry was from a
>>>>> form, I would have no problem, but the data will be uploaded from a
>>>>> different source, how would I go about dropping the middle initial?
>>>>>
>>>>> Would I use regex??
>>>>>
>>>>> Thank you,
>>>>> Kevin
>>>>
>>>> $name="Kevin R. Davis";
>>>> $a=split(" ",$name);
>>>> print $a[0]." ".$a[count($a)-1];
>>>>
>>>> It should print:
>>>> Kevin Davis
>>>
>>> What about "John Smith Jr"?

>>
>> Or "Carlos Salinas de Gortari"?
>>
>> To cut to the important point, "dropping middle initial" is a kind
>> of simple problem surround by worm-cans with very weak lids. Pretty
>> much the least damaging thing you can do is drop punctuation and any
>> single-letter (not single character, just Latin letter) words, using two
>> passes with regexp processing. Usually if someone has put something into
>> a field on form asking for their name, whatever they've put there is
>> important to them.
>>
>> You'll still piss off will.i.am of The Black-Eyed Peas even with that
>> simple step.

>
> and anyone with the surname De'Ath.
>
>
>


<?php
$name="Kevin R. De'Ath";
$a=split(" ",$name);
print $a[0]." ".$a[count($a)-1];
print "\n";

// Second solution, so J. R. R. Tolkien is also handled correctly
$name="J. R. R. Tolkien";
$a=split(" ",$name);
for ($f=0; $f<count($a); $f++)
if (substr($a[$f],strlen($a[$f])-1,1)!="." or $f==0) print
$a[$f]." ";
print "\n";

?>


output:
Kevin De'Ath
J. Tolkien
Reply With Quote
  #11 (permalink)  
Old 06-05-2012, 06:33 AM
Nick Brooks
Guest
 
Posts: n/a
Default Re: PHP Concatenate

Cool stuff guys!
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 02:22 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.