unicodeTransCoder = new TranscodeUnicode(); $this->punycodeEncoder = new FromPunycode(); } public function convert(string $host): string { // Drop any whitespace around $input = trim($host); $hostLabels = explode('.', $input); foreach ($hostLabels as $index => $label) { $return = $this->punycodeEncoder->convert($label); if (!$return) { $return = $label; } $hostLabels[$index] = $return; } return implode('.', $hostLabels); } }