Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does someone have a PHP function to properly capitalize people names?

Tags:

php

I'm looking for a function to properly capitalize names like McDonald, FitzGerald, MacArthur, O'Lunney's, Theo de Raadt, etc.

Does anyone know of one that works resonably well? I'm guessing any function is not going to support every possibility.

Of course ucwords alone doesn't work for this because it just capitalize the first letter of every word.

Edit: I know there are going to be problems and all the possibility are not going to be supported. But the issue right now is I have a database of around 50 000 names that are mostly entered in all caps and it would be a pain in the ass to have to edit each one without causing spelling errors. Having a script that causes a problem with 20% would be a whole lot faster and result in a lot fewer errors.

like image 630
Darryl Hein Avatar asked Jul 30 '09 18:07

Darryl Hein


2 Answers

Maybe you need something like this ucwords function note

like image 167
inakiabt Avatar answered Sep 28 '22 23:09

inakiabt


You're probably aware of this, but one huge problem you'll face is that there's more than one "correct" capitalisation of some names - in your example I'd disagree with FitzGerald, for example.

like image 39
John Carter Avatar answered Sep 28 '22 21:09

John Carter