Piwik\UrlHelper::getParseUrlReverse PHP Method

getParseUrlReverse() public static method

Copied from the PHP comments at http://php.net/parse_url.
public static getParseUrlReverse ( array $parsed ) : false | string
$parsed array Result of [parse_url](http://php.net/manual/en/function.parse-url.php).
return false | string The URL or `false` if `$parsed` isn't an array.
    public static function getParseUrlReverse($parsed)
    {
        if (!is_array($parsed)) {
            return false;
        }
        $uri = !empty($parsed['scheme']) ? $parsed['scheme'] . ':' . (!strcasecmp($parsed['scheme'], 'mailto') ? '' : '//') : '';
        $uri .= !empty($parsed['user']) ? $parsed['user'] . (!empty($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : '';
        $uri .= !empty($parsed['host']) ? $parsed['host'] : '';
        $uri .= !empty($parsed['port']) ? ':' . $parsed['port'] : '';
        if (!empty($parsed['path'])) {
            $uri .= !strncmp($parsed['path'], '/', 1) ? $parsed['path'] : (!empty($uri) ? '/' : '') . $parsed['path'];
        }
        $uri .= !empty($parsed['query']) ? '?' . $parsed['query'] : '';
        $uri .= !empty($parsed['fragment']) ? '#' . $parsed['fragment'] : '';
        return $uri;
    }

Usage Example

Beispiel #1
0
 /**
  * Build the full URL from the prefix ID and the rest.
  *
  * @param string $url
  * @param integer $prefixId
  * @return string
  */
 public static function reconstructNormalizedUrl($url, $prefixId)
 {
     $map = array_flip(self::$urlPrefixMap);
     if ($prefixId !== null && isset($map[$prefixId])) {
         $fullUrl = $map[$prefixId] . $url;
     } else {
         $fullUrl = $url;
     }
     // Clean up host & hash tags, for URLs
     $parsedUrl = @parse_url($fullUrl);
     $parsedUrl = PageUrl::cleanupHostAndHashTag($parsedUrl);
     $url = UrlHelper::getParseUrlReverse($parsedUrl);
     if (!empty($url)) {
         return $url;
     }
     return $fullUrl;
 }
All Usage Examples Of Piwik\UrlHelper::getParseUrlReverse