Out of a MySQL database I have a list of names like
- Smith
- Frank
- Dent MD
- Smith Sr.
- Jones, jr.
- Smith-Jones
- O'Toole
I need to get that list to be
- smith
- frank
- dent
- smith
- jones
- smith-jones
- otoole
By format I mean I only want the "main" part of the last name eliminating any
- non-alphanumeric characters
- spaces
- Titles (jr, sr, MD, etc...)
I realize in some cases this is "changing" the person's name but it's not being used in any way that they see.
Right now I am doing something like:
$toReplace = array('.', ',', '-', ' jr', ' sr', ' MD', ' DO', "'", ' ');
//For each result from my query
$lname = str_replace($toReplace, '', $row_rsgetUsers['lname']);
$lname = strtolower($lname);
Then, after awhile a name shows up like Wright CISA
so I then have to update my $toReplace
array to account for that. (I have no control over the input of the names)
Is that the best way to go about doing this or is there a better way/library out there I should be using that eliminates the need for me to manually update my $toReplace
array occasionally?