/** * Removes given parameter from the url * * @param $url * @param $param * @return string */ public function removeQueryParamFromUrl($url, $param) { $modified_url = $url; $url_parts = NostoHttpRequest::parseUrl($url); if ($url_parts !== false && isset($url_parts['query'])) { $query_array = NostoHttpRequest::parseQueryString($url_parts['query']); if (isset($query_array[$param])) { unset($query_array[$param]); if (empty($query_array)) { unset($url_parts['query']); } else { $url_parts['query'] = http_build_query($query_array); } $modified_url = NostoHttpRequest::buildUrl($url_parts); } } return $modified_url; }
/** * Tests the "buildUrl" helper method. */ public function testHttpRequestBuildUrl() { $url_parts = NostoHttpRequest::parseUrl(sprintf('http://localhost:%d/tmp/?param1=first¶m2=second#fragment1=test', self::CURL_TEST_PORT)); $url = NostoHttpRequest::buildUrl($url_parts); $this->assertEquals(sprintf('http://localhost:%d/tmp/?param1=first¶m2=second#fragment1=test', self::CURL_TEST_PORT), $url); }