FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » PHP Concatenate
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
PHP Concatenate [message #178190] Mon, 21 May 2012 18:47 Go to next message
Kevin Davis is currently offline  Kevin Davis
Messages: 5
Registered: May 2012
Karma: 0
Junior Member
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
Re: PHP Concatenate [message #178192 is a reply to message #178190] Mon, 21 May 2012 19:17 Go to previous messageGo to next message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma: 0
Senior Member
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
Re: PHP Concatenate [message #178194 is a reply to message #178190] Mon, 21 May 2012 19:19 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
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
Re: PHP Concatenate [message #178195 is a reply to message #178190] Tue, 22 May 2012 11:34 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
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.
Re: PHP Concatenate [message #178196 is a reply to message #178194] Tue, 22 May 2012 12:21 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: PHP Concatenate [message #178197 is a reply to message #178196] Tue, 22 May 2012 13:42 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
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.
Re: PHP Concatenate [message #178198 is a reply to message #178197] Tue, 22 May 2012 14:21 Go to previous messageGo to next message
Paul Herber is currently offline  Paul Herber
Messages: 26
Registered: February 2011
Karma: 0
Junior Member
On Tue, 22 May 2012 08:42:54 -0500, "Peter H. Coffin" <hellsop(at)ninehells(dot)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/
Re: PHP Concatenate [message #178199 is a reply to message #178198] Tue, 22 May 2012 15:37 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Paul Herber wrote:
> On Tue, 22 May 2012 08:42:54 -0500, "Peter H. Coffin" <hellsop(at)ninehells(dot)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.
Re: PHP Concatenate [message #178202 is a reply to message #178198] Tue, 22 May 2012 18:18 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 22-05-2012 16:21, Paul Herber wrote:
> On Tue, 22 May 2012 08:42:54 -0500, "Peter H. Coffin" <hellsop(at)ninehells(dot)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?
Re: PHP Concatenate [message #178203 is a reply to message #178198] Tue, 22 May 2012 18:30 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 22-05-2012 16:21, Paul Herber wrote:
> On Tue, 22 May 2012 08:42:54 -0500, "Peter H. Coffin" <hellsop(at)ninehells(dot)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
Re: PHP Concatenate [message #178329 is a reply to message #178190] Tue, 05 June 2012 06:33 Go to previous message
Nick Brooks is currently offline  Nick Brooks
Messages: 1
Registered: June 2012
Karma: 0
Junior Member
Cool stuff guys!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: implode/explode vs serialize/unserialize
Next Topic: Google groups - melhoria da plataforma
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 20:07:01 GMT 2024

Total time taken to generate the page: 0.02431 seconds