// Strip parenthetical and quoted nicknames so "James (Neal) Conrad" // and "Bruce (Bernadette) Weinberg" match the same as the plain name. $cleanName = preg_replace('/\([^)]*\)/', ' ', $caller['caller_name'] ?? ''); $cleanName = preg_replace('/"[^"]*"/', ' ', $cleanName); $cleanName = trim(preg_replace('/\s+/', ' ', $cleanName)); $nameParts = $cleanName !== '' ? preg_split('/\s+/', $cleanName) : []; $cleanFirst = $nameParts[0] ?? ''; $cleanLast = count($nameParts) > 1 ? end($nameParts) : ($caller['caller_last'] ?? ''); $lastPrefix = strtoupper(mb_substr($cleanLast, 0, 4)); $firstInitial = $cleanFirst !== '' ? strtoupper(mb_substr($cleanFirst, 0, 1)) : '';