3v4l.org

run code in 300+ PHP versions simultaneously
<?php $value = utf8_decode('Österreich'); $encoding = mb_detect_encoding($value); $country = $value; if ($encoding != 'ISO-8859-1') { $country = mb_convert_encoding($country, 'ISO-8859-1', $encoding); } $country = mb_strtolower($country, 'ISO-8859-1'); switch ($country) { case 'deutschland': case 'de': echo "de"; break; case 'österreich': case 'at': case 'oesterreich': echo "at"; break; default: throw new Exception('Invalid country: ' . $value); break; }

preferences:
37.81 ms | 402 KiB | 5 Q