Skip to content

Instantly share code, notes, and snippets.

@zhukovsergei
Last active December 28, 2015 11:57
Show Gist options
  • Save zhukovsergei/d7d71fa742bcf025af58 to your computer and use it in GitHub Desktop.
Save zhukovsergei/d7d71fa742bcf025af58 to your computer and use it in GitHub Desktop.
Разбор, изменение параметров URL string
<?php
$url = 'http://example.com/search?keyword=test&category=1&tags[]=fun&tags[]=great';
$url_parts = parse_url($url);
parse_str($url_parts['query'], $params);
$params['category'] = 2; // Overwrite if exists
$params['tags'][] = 'cool'; // Allows multiple values
// Note that this will url_encode all values
$url_parts['query'] = http_build_query($params);
// If you have pecl_http
echo http_build_url($url_parts);
// If not
echo $url_parts['scheme'] . '://' . $url_parts['host'] . $url_parts['path'] . '?' . $url_parts['query'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment