Latest 100 public snipts »
hongster's
snipts » get
showing 1-1 of 1 snipts for get
-
∞ Dynamically change URL query string.
<?php function modifyQuery($url, $query) { // Convert query string to array if (! is_array($query)) { parse_str($query, $query); } // Extract the components in a url string $components = parse_url($url); if (! isset($components['query'])) { $components['query'] = ''; } parse_str($components['query'], $components['query']); // Combine the queries $components['query'] = array_merge($components['query'], $query); // Put the components together $url = isset($components['host']) ? "{$components['scheme']}://{$components['host']}" : '/'; $url .= isset($components['path']) ? $components['path'] : '/'; $url .= empty($components['query']) ? '' : '?'.http_build_query($components['query']); $url .= isset($components['fragment']) ? "#{$components['fragment']}" : ''; return $url; } ?>


