> 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