Normalising Names

From: Date: Fri, 14 May 2004 03:22:14 +0000
Subject: Normalising Names
Groups: php.general 
Request: Send a blank email to php-general+get-186197@lists.php.net to get a copy of this message
Hi all, Can someone point me in the direction of a function/library/tutorial on normalising and formatting user-inputted names so that they have the correct capitalisation etc? This will work for MOST situations I'm aware of: <? $name = ucwords(strtolower($name)); ?> BUT, this will not work in the following cases: 1. where a word will NOT want a first letter capital (like "Chris de Vidal" off this list) 2. a name may require mixed case (for Mc and Mac, like Jeff McKeon off this list) 3. where there are hyphened names (like Mary-Kate Smith, and Fred Smith-Jones) 4. a name contains an apostrophe (like O'Connor) 5. Mackenzie (and some others) are probably exceptions to case #2. 5. there are probably many more cases which I don't see regularly, or have forgotten. There's a reasonable example on http://www.php.net/ucfirst by Lee Benson, but it doesn't handle case #1 (Chris de Vidal). In addition, it doesn't take into account special characters, like ü which may need to be uppercased to Ü. My current thinking is to normalise everything to lowercase, uppercase the words, then handle as many special cases as I can, but KNOWING all the special cases is half the battle. And yes, I've done a Google, but searching for terms like "name" and "capital" and "format" return thousands of irrelevant results amongst a few gems :) --- Justin French http://indent.com.au

« previous php.general (#186197) next »