1
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
this url brings me the image with different size).
I wish I could replace only this query string value, the width
, and replace by another.
I want to do it from a array
. I mean, I’m gonna have one array
with the values I want to replace in the query string of that url, but I cannot 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, transforming the value of 500
for 200
, making it so:
http://site.com/images/?sistema=3&size=200&type=png;
How 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));
That would have to come back:
'http://site.com/images/?sistema=3&size=200&type=png;'
How could I create this function in PHP? Can anyone help me?
how is your array?
– Raphael Caldas
Look at the last example...
array('size' => 200)
... I already asked the question :)– Wallace Maxters
Wouldn’t it be easier to use one
str_replace
no? That way:$size = 200;
$url = 'http://site.com/images/?sistema=3&size=500&type=png';
and at printar time put so$url = str_replace( '&size=500', '&size='.$size, transforma_query_string($url) );
– Raphael Caldas