I am trying to determine a method to uppercase a surname; however, excluding the lowercase prefix.
Example of names and their conversion:
- MacArthur -> MacARTHUR
- McDavid -> McDAVID
- LeBlanc -> LeBLANC
- McIntyre -> McINTYRE
- de Wit -> de WIT
There are also names that would contain the surnames that would need to be fully capitalized, so a simple function to identify the prefix such as strchr()
would not suffice:
- Macmaster -> MACMASTER
- Macintosh -> MACINTOSH
The PHP function mb_strtoupper()
is not appropriate, as it capitalizes the complete string. Similarly strtoupper()
is not appropriate, and loses accents on accented names as well.
There are some answers around SO that partly answer the question, such as : Capitalization using PHP
However, the common shortfall is assuming that all names with a surname as as Mac
are followed with a capital.
The names are capitalized properly in the database, so we can assume that a name spelled as Macarthur is correct, or MacArthur is correct for another person.