From 40350e293f2ff64b810f44bc40b77cde0af51a73 Mon Sep 17 00:00:00 2001 From: Marc Michalsky forumZFD Date: Mon, 14 Dec 2020 17:20:15 +0100 Subject: [PATCH] implement class for string operations --- .../Utils/StringOperations.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 CRM/TwingleCampaign/Utils/StringOperations.php diff --git a/CRM/TwingleCampaign/Utils/StringOperations.php b/CRM/TwingleCampaign/Utils/StringOperations.php new file mode 100644 index 0000000..b737c70 --- /dev/null +++ b/CRM/TwingleCampaign/Utils/StringOperations.php @@ -0,0 +1,55 @@ + 1) { + $lastname = array_pop($names); + $test = $names[count($names) - 1]; + $lastnamePrefixes = ['da', 'de', 'der', 'van', 'von']; + if (in_array($test, $lastnamePrefixes)) { + if ($test == 'der' && + $names[count($names) - 2] == 'van' || + $names[count($names) - 2] == 'von' + ) { + $lastname = implode(' ', array_splice($names, -2)) + . ' ' . $lastname; + } + else { + array_pop($names); + $lastname = $test . ' ' . $lastname; + } + } + $firstnames = implode(" ", $names); + return ['firstnames' => $firstnames, 'lastname' => $lastname]; + } + return $string; + } +} \ No newline at end of file