public static getPathAndQueryFromUrl ( string $url ) : string | ||
$url | string | The URL. |
return | string | eg, `/test/index.php?module=CoreHome` if `$url` is `http://piwik.org/test/index.php?module=CoreHome`. |
public static function getPathAndQueryFromUrl($url)
{
$parsedUrl = parse_url($url);
$result = '';
if (isset($parsedUrl['path'])) {
if (substr($parsedUrl['path'], 0, 1) == '/') {
$parsedUrl['path'] = substr($parsedUrl['path'], 1);
}
$result .= $parsedUrl['path'];
}
if (isset($parsedUrl['query'])) {
$result .= '?' . $parsedUrl['query'];
}
return $result;
}
/** * Returns path component from a URL * * @param string $url * @return string path */ function getPathFromUrl($url) { $path = UrlHelper::getPathAndQueryFromUrl($url); if (empty($path)) { return 'index'; } return $path; }