I have the following url that is returned to me by a webservice in a certain part of my application. But it comes with a query string that determines the size of the image (according to the parameter width
that url brings me the image with different size).
I would like to be able to replace only this value of the query string, width
, and replace with another.
I want to do this from a array
. That is, I will have a array
with the values that I want to replace in the query string of this url, but I can not remove the others.
For example. If I have this url:
http://site.com/images/?sistema=3&size=500&type=png;
I want to transform it by transforming the value from 500
to 200
, making it like this:
http://site.com/images/?sistema=3&size=200&type=png;
As I want to do through a array
, I need something like this:
// retornado pelo webservice
$url = 'http://site.com/images/?sistema=3&size=500&type=png';
$url = transforma_query_string($url, array('size' => 200));
This would have to return:
'http://site.com/images/?sistema=3&size=200&type=png;'
How could I do to create this function in PHP? Can anyone help me?