<?php

/**

 * Ghana Phone Number Formatter

 * Formats Ghanaian phone numbers to international format

 */



function formatGhanaPhone($phone) {

    // Remove all non-numeric characters

    $phone = preg_replace('/[^0-9]/', '', $phone);

    

    // Check if it's a Ghana number

    if (strlen($phone) == 9) {

        // 9-digit local format (e.g., 244567890)

        return '233' . $phone;

    } elseif (strlen($phone) == 10 && substr($phone, 0, 1) == '0') {

        // 10-digit with leading zero (e.g., 0244567890)

        return '233' . substr($phone, 1);

    } elseif (strlen($phone) == 12 && substr($phone, 0, 3) == '233') {

        // Already in international format

        return $phone;

    }

    

    // Return original if can't format

    return $phone;

}



function validateGhanaPhone($phone) {

    $formatted = formatGhanaPhone($phone);

    return strlen($formatted) == 12 && substr($formatted, 0, 3) == '233';

}

?>