The idea is to have a function to easily manipulate URL’s query string by simply giving:
- string – URL to be manipulated
- array – the query strings in form of array. Translating
'key' => 'value'
into&key=value
Here’s the code that I came up with. I post it here for future reference:
It can be simply used like this:
$url = 'http://fikrirasy.id/?first_name=fikri&last_name=rasyid;
$query_strings = array(
'last_name' => 'nolan'
);
$new_url = fr_modify_url( $url, $query_strings ); // would return 'http://fikrirasy.id/?first_name=fikri&last_name=nolan