[PHP] Re:[PHP] Capitalising Personal Names

2003-03-11 Thread Geoff Caplan
Hi folks,

I have now hacked out a little name module on the lines discussed.

The aim is to capitalise names which user has entered in all
upper or all lower case. It would be useful in situations such as an
e-commerce checkout where ease of use is more important than accuracy
and you don't want to hold them asking them to re-enter.

It can handle full names, first names or last names.
It deals with a range of prefixes (von, van, de la, ap, St. etc etc),
suffixes (III, 3rd etc) and hyphenation (Twistleton-Crump).

It can produce prefixes in full name format

Helmut von Battenburg

and salutation format:

Dear Mr Von Battenburg

as required.

If anyone wants a look and to do a bit of testing, please drop me a
line and I'll send the code. Also, I am sure it is anglo-centric. I
would be grateful if someone with a knowledge of Spanish, Portuguese
etc names wants to add more rules to internationalise it.

Once I have had some feedback, I will post the code somewhere, as
there doesn't seem to be anything like this in PHP, for some reason.

Cheers

Geoff Caplan
Advantae Ltd

http://www.advantae.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capitalising Personal Names

2003-02-28 Thread Danny Shepherd
Hi,

Well it's hardly rocket science - a flick through the manual and I came up
with :

$name=ucwords(strtolower($name));

HTH

Danny.

- Original Message -
From: Geoff Caplan [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, February 28, 2003 10:31 AM
Subject: [PHP] Capitalising Personal Names


 Hi folks,

 I need to clean up the capitalisation of user-entered personal names.

 Once you start thinking about it, you realise it is a non-trivial
 issue, but previous discussions on the list presented only very
 partial solutions.

 In Perl, there are Cpan modules such as namecase and nameparse which
 handle this quite well. Does anyone have anything similar in PHP?

 Thanks
 --

 Geoff Caplan
 Advantae Ltd


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capitalising Personal Names

2003-02-28 Thread Justin French
What about DeSilva And McSomething?

Justin


on 28/02/03 10:11 PM, Danny Shepherd ([EMAIL PROTECTED]) wrote:

 Hi,
 
 Well it's hardly rocket science - a flick through the manual and I came up
 with :
 
 $name=ucwords(strtolower($name));
 
 HTH
 
 Danny.
 
 - Original Message -
 From: Geoff Caplan [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, February 28, 2003 10:31 AM
 Subject: [PHP] Capitalising Personal Names
 
 
 Hi folks,
 
 I need to clean up the capitalisation of user-entered personal names.
 
 Once you start thinking about it, you realise it is a non-trivial
 issue, but previous discussions on the list presented only very
 partial solutions.
 
 In Perl, there are Cpan modules such as namecase and nameparse which
 handle this quite well. Does anyone have anything similar in PHP?
 
 Thanks
 --
 
 Geoff Caplan
 Advantae Ltd
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Capitalising Personal Names

2003-02-28 Thread Jon Haworth
Hi Danny,

  I need to clean up the capitalisation of user-entered personal names.
 
 Well it's hardly rocket science - a flick through the manual and I 
 came up with :
 $name=ucwords(strtolower($name));

While that would work in many cases, how do you catch exceptions such as the
following?

?php

  $names[] = Ludwig van Beethoven;
  $names[] = Ronald MacDonald;
  $names[] = Alexis de Tocqueville;
  $names[] = Tim O'Reilly;

  foreach ($names as $name)
echo $name.  - . ucwords(strtolower($name)). br /;

?

Cheers
Jon

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capitalising Personal Names

2003-02-28 Thread Joshua Moore-Oliva
What is someone spells their name Desilva?

On February 28, 2003 06:21 am, Justin French wrote:
 What about DeSilva And McSomething?

 Justin

 on 28/02/03 10:11 PM, Danny Shepherd ([EMAIL PROTECTED]) wrote:
  Hi,
 
  Well it's hardly rocket science - a flick through the manual and I came
  up with :
 
  $name=ucwords(strtolower($name));
 
  HTH
 
  Danny.
 
  - Original Message -
  From: Geoff Caplan [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Friday, February 28, 2003 10:31 AM
  Subject: [PHP] Capitalising Personal Names
 
  Hi folks,
 
  I need to clean up the capitalisation of user-entered personal names.
 
  Once you start thinking about it, you realise it is a non-trivial
  issue, but previous discussions on the list presented only very
  partial solutions.
 
  In Perl, there are Cpan modules such as namecase and nameparse which
  handle this quite well. Does anyone have anything similar in PHP?
 
  Thanks
  --
 
  Geoff Caplan
  Advantae Ltd
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capitalising Personal Names

2003-02-28 Thread Joshua Moore-Oliva
Make a perl script that does what you want and use exec to pipe to it then :)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capitalising Personal Names

2003-02-28 Thread Awlad Hussain
Have a javascript alert like Are you 100% sure you haven't typed your name
wrong :)

Other option is to create name dictionary then compare..

- Original Message -
From: Joshua Moore-Oliva [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Friday, February 28, 2003 11:35 AM
Subject: Re: [PHP] Capitalising Personal Names


 What is someone spells their name Desilva?

 On February 28, 2003 06:21 am, Justin French wrote:
  What about DeSilva And McSomething?
 
  Justin
 
  on 28/02/03 10:11 PM, Danny Shepherd ([EMAIL PROTECTED]) wrote:
   Hi,
  
   Well it's hardly rocket science - a flick through the manual and I
came
   up with :
  
   $name=ucwords(strtolower($name));
  
   HTH
  
   Danny.
  
   - Original Message -
   From: Geoff Caplan [EMAIL PROTECTED]
   To: [EMAIL PROTECTED]
   Sent: Friday, February 28, 2003 10:31 AM
   Subject: [PHP] Capitalising Personal Names
  
   Hi folks,
  
   I need to clean up the capitalisation of user-entered personal names.
  
   Once you start thinking about it, you realise it is a non-trivial
   issue, but previous discussions on the list presented only very
   partial solutions.
  
   In Perl, there are Cpan modules such as namecase and nameparse which
   handle this quite well. Does anyone have anything similar in PHP?
  
   Thanks
   --
  
   Geoff Caplan
   Advantae Ltd
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capitalising Personal Names

2003-02-28 Thread Joshua Moore-Oliva
well, as a last resort if you can find the perl module that does that conver 
the code to php...

it's probably just a bunch of regular expressions, and php has a perl compat 
regular expressions interface..

Josh.

On February 28, 2003 07:01 am, Geoff Caplan wrote:
 Joshua,

 JMO Make a perl script that does what you want and use exec to pipe to it
 then :)

 This is certainly a sensible solution. But I'd have to learn enough
 about Perl to do it. And I think it would be slow for large volumes of
 names - exec seems to be slow in general, for some reason.

 It would be good to have a native PHP solution. I can't be the only
 one who needs to clean up names...

 Geoff Caplan


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capitalising Personal Names

2003-02-28 Thread Chris Hayes

 What is someone spells their name Desilva?

 On February 28, 2003 06:21 am, Justin French wrote:
  What about DeSilva And McSomething?
I found another thread on this subject here: 
http://www.phpbuilder.com/mail/php-general/2002102/2138.php, but i did not 
read it.

Looking at all the examples here,  i'ld only interfere if all chars are 
upper or all are lower. Only in those cases i would apply the simple 
uc-first. Then you would only upset ani difranco who wants to be all 
lowercase. (Maybe you should run a check on that name :) ).





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Capitalising Personal Names

2003-02-28 Thread John W. Holmes
 DS Well it's hardly rocket science -
 
 I'm afraid it's a bit more complicated than that. There are hypenated
 names, names with lower-case words like de and von, Irish style names
 (O'Connell), Scots style names (MacDonald, McCalman) etc etc. And
 there are exceptions in most of these cases too. Plus there other
 conventions in other cultures.

In addition to the other remarks, don't forget about roman numerals,
either. I'm John Holmes III (the 3rd), but I don't use the numerals.
Some people do, however. 

The best solution I see is to start building yourself some arrays.

The first array would be those middle words that should be all
lowercase:

$lcase_words = array('de','von');

And roman numerals

$rn_words = array('i','ii','iii','iv','v','vi','vii','viii','ix','x');

(assuming there's no 11th generation people out there... I'm sure that's
a safe assumption)

And then the sequences that can start a word after which there should be
a capitol letter:

$st_words = array('mc','mac','de');

To process the names, first convert everything to lowercase. Then break
apart the name on any non-alpha character. Save the non-alpha character,
too, so you can rebuild the word. Regular expression will be best for
that, probably. Then, loop through each part of the name. 

1. If the part matches one of the $lcase_words, do nothing, add the part
to the final name and go onto the next part.

2. If the part matches one of the $rn_words, upper case the whole thing,
add that part to the final name, and go on to the next part.

3. If the first X characters matches one of the $st_words elements,
upper case the first letter, then the next character after the strlen()
of the $st_words element that matches. Add that part to the final name
and go onto the next part.

4. If the part is a non-alpha character, just add it to the final name
and move onto the next part. 

Anyone see any issues with that? I don't have time to write the actual
code now, I'll do it later. It'll make for a good tip to put into
PHP|Architect. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Capitalising Personal Names

2003-02-28 Thread Dave O'Meara
Maybe a script that tests the entry, and asks the user to reconfirm
nonstandard spelling and capitalization.  Something like...

if ($name != ucwords($name) {
//script that suggests ucwords($name) as a possible correction
//but allows the user to confirm nonstandard capitalization scheme
//by re-entering the name.
}

Then what goes into the database is either
a) standard format, or
b) has been confirmed by the user.

Dave O'Meara


Jon Haworth [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi Danny,

   I need to clean up the capitalisation of user-entered personal names.
 
  Well it's hardly rocket science - a flick through the manual and I
  came up with :
  $name=ucwords(strtolower($name));

 While that would work in many cases, how do you catch exceptions such as
the
 following?

 ?php

   $names[] = Ludwig van Beethoven;
   $names[] = Ronald MacDonald;
   $names[] = Alexis de Tocqueville;
   $names[] = Tim O'Reilly;

   foreach ($names as $name)
 echo $name.  - . ucwords(strtolower($name)). br /;

 ?

 Cheers
 Jon



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php