change _booking_ucname function to handle names like McClure

This commit is contained in:
Nathan Coad
2018-01-18 12:13:56 +11:00
parent 584376bf25
commit c70b05922d
2 changed files with 34 additions and 4 deletions

View File

@@ -31,13 +31,41 @@ function _booking_remove_emoji($text) {
* Taken from http://php.net/manual/en/function.ucwords.php
*/
function _booking_ucname($string) {
$string = ucwords(strtolower($string));
$all_uppercase = '';
$all_lowercase = 'De La|De Las|Der|Van De|Van Der|Vit De|Von|Or|And';
$prefixes = 'Mc';
$suffixes = "'S";
// captialize all first letters
$string = preg_replace('/\\b(\\w)/e', 'strtoupper("$1")', strtolower(trim($string)));
if ($all_uppercase) {
// capitalize acronymns and initialisms e.g. PHP
$string = preg_replace("/\\b($all_uppercase)\\b/e", 'strtoupper("$1")', $string);
}
if ($all_lowercase) {
// decapitalize short words e.g. and
// all occurences will be changed to lowercase
$string = preg_replace("/\\b($all_lowercase)\\b/e", 'strtolower("$1")', $string);
}
if ($prefixes) {
// capitalize letter after certain name prefixes e.g 'Mc'
$string = preg_replace("/\\b($prefixes)(\\w)/e", '"$1".strtoupper("$2")', $string);
}
if ($suffixes) {
// decapitalize certain word suffixes e.g. 's
$string = preg_replace("/(\\w)($suffixes)\\b/e", '"$1".strtolower("$2")', $string);
}
/*
$string = ucwords(strtolower($string));
foreach (array('-', '\'') as $delimiter) {
if (strpos($string, $delimiter)!==false) {
$string =implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
if (strpos($string, $delimiter) !== false) {
$string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
}
}
*/
return $string;
}