public static function sanitizeCountry($locale, $default = null)
    {
        if ($locale instanceof Locale) {
            return $locale->getCountry();
        }

        if ($default) {
            $default = Locale::sanitizeCountry($default, null);
        }

        $locale = (string) $locale;
        $locale = trim($locale);

        if (!$locale || !preg_match("/(?<country>[a-z]{2})$/ui", $locale, $found)) {
            return $default;
        }

        return Text::toUpper($found['country']);
    }
public static function sanitizeCountry($locale, $default = null)
    {
        if ($locale instanceof Locale) {
            return $locale->getCountry();
        }

        if ($default) {
            $default = Locale::sanitizeCountry($default, null);
        }

        $locale = (string) $locale;
        $locale = trim($locale);

        if (!$locale || !preg_match("/(?<country>[a-z]{2})$/ui", $locale, $found)) {
            return $default;
        }

        return Text::toUpper($found['country']);
    }
public static function sanitizeCountry ( $ locale , $ default = null ) { if ( $ locale instanceof Locale ) { return $ locale -> getCountry ( ) ; } if ( $ default ) { $ default = Locale :: sanitizeCountry ( $ default , null ) ; } $ locale = ( string ) $ locale ; $ locale = trim ( $ locale ) ; if ( ! $ locale || ! preg_match ( "/(?<country>[a-z]{2})$/ui" , $ locale , $ found ) ) { return $ default ; } return Text :: toUpper ( $ found [ 'country' ] ) ; }
Sanitize given country from locale.

Must be a simple locale without code set, currency or similar (e. g. "de_DE" or "de-de" or "DE").

@param string|Locale $locale
@param string|Locale $default [optional] The default locale to return if $locale is invalid

@return null|string
Sanitize given country from locale .