encode($domain); } return substr_replace($url, $new_domain, $position, strlen($domain)); } /** * Convert IDNA (punycode) domain into UTF-8 * * @param string $url * @return string */ public static function decodeIdna($url) { if (preg_match('@[:/#]@', $url)) { $domain = parse_url($url, \PHP_URL_HOST); $position = strpos($url, $domain); if ($position === false) { return $url; } } else { $domain = $url; $position = 0; } if (function_exists('idn_to_utf8')) { $new_domain = idn_to_utf8($domain); } else { $decoder = new \TrueBV\Punycode(); $new_domain = $decoder->decode($domain); } return substr_replace($url, $new_domain, $position, strlen($domain)); } }