3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strs = [ 'Ostroměr', 'Šventaragis', 'Świętopełk', 'Dušan', 'Živko', ]; /** * Decodes a url-encoded path segment. */ function decodePathSegment(string $path): string { $path = rawurldecode($path); $encoding = mb_detect_encoding($path, ['UTF-8', 'ISO-8859-1']); switch ($encoding) { case 'ISO-8859-1': $path = utf8_encode($path); } return $path; } foreach($strs as $str) { var_dump(decodePathSegment($str)); }

preferences:
34.73 ms | 407 KiB | 5 Q