Last active
December 28, 2015 11:57
-
-
Save zhukovsergei/d7d71fa742bcf025af58 to your computer and use it in GitHub Desktop.
Разбор, изменение параметров URL string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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