I use this script to ensure surnames are 'propercase' in php/mysql
This script sets the first character as uppercase and the first character after an apostraphe to uppercase as well.
I'd like to add some additional checks.
For example I'd like to check for hyphenated names and double barrelled names
ie
jones-smith becomes Jones-Smith
and
SMITH JONES becomes Smith Jones
I suspect we need an array to manage the apostraphe, hyphen & space.
thanks
Michael
if (strstr($surname, '\'')) {
// Divide the surname into multiple parts, divided by apostrophes
$surnameDivided = explode('\'', $surname);
// Capitalize the first letter of each "part" of the surname
foreach ($surnameDivided as &$part) {
$part = ucfirst(strtolower($part));
}
// Bring the surname together again, with apostrophes
$surname = implode('\'', $surnameDivided);
}
// If there is not an apostrophe in the surname,
// capitalize the first letter as you normally would
else {
$surname = ucfirst(strtolower($surname));
}
This prints,
Jones Smith | Johnes Smith | Jone'S Smith | Jones-Smith
Open in new window