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; }