<?php

/**

 * Name Formatter

 * Properly capitalizes names (handles Ghanaian names with prefixes)

 */



function formatName($name) {

    if (empty($name)) {

        return '';

    }

    

    // Handle compound names with prefixes (e.g., "Osei", "Nana", "Abena")

    $name = trim($name);

    $name = strtolower($name);

    

    // List of words that should remain lowercase in names

    $lowercasePrefixes = ['of', 'de', 'van', 'von', 'der', 'den'];

    

    $parts = explode(' ', $name);

    $formatted = [];

    

    foreach ($parts as $part) {

        if (in_array($part, $lowercasePrefixes)) {

            $formatted[] = $part;

        } else {

            $formatted[] = ucfirst($part);

        }

    }

    

    return implode(' ', $formatted);

}



function formatGhanaianName($name) {

    $name = formatName($name);

    

    // Handle specific Ghanaian naming patterns

    $patterns = [

        '/^nana /i' => 'Nana ',

        '/^nananom /i' => 'Nananom ',

        '/^obaapa /i' => 'Obaapa ',

        '/^osagyefo /i' => 'Osagyefo '

    ];

    

    foreach ($patterns as $pattern => $replacement) {

        if (preg_match($pattern, $name)) {

            $name = preg_replace($pattern, $replacement, $name);

        }

    }

    

    return $name;

}

?>