encode($domain); } return $domain; } return false; } /** * Decodes punycoded'd URL * @param string $url URL * @return mixed string with decoded URL on success, boolean false otherwise */ public static function decode($url) { $url = self::fix($url); if ($url) { $components = parse_url($url); $host = $components['host'] . (empty($components['port']) ? '' : ':' . $components['port']); if (strpos($host, self::PUNYCODE_PREFIX) !== false) { $idn = new \Net_IDNA2(); $host = $idn->decode($host); } $path = !empty($components['path']) ? $components['path'] : ''; return $host . rtrim($path, '/'); } return false; } /** * Resolves relative url * * @param string $url relative url * @param string $base url base * * @return string $url resolved url */ public static function resolve($url, $base) { if ($url[0] == '/') { $_pbase = parse_url(self::fix($base)); $url = $_pbase['protocol'] . '://' . $_pbase['host'] . $url; } else { $url = $base . '/' . $url; } return $url; } }