andufo andufo -4 years ago 111
PHP Question

PHP removing querystring variable from a string

This is $postfields value:

image=%40E%3A%5Cdev%5Cphoto.jpg&oauth_timestamp=1291739697&oauth_token=123456&tile=true


I need to take out any the image=xxxxx part of that value so i only have this at the end:

oauth_timestamp=1291739697&oauth_token=123456&tile=true


I tried explode() and parse_str() approaches with no success. The best solution would be to find any image=xxxxx inside the long string, then convert it to an array like this:

$array['image'] = '%40E%3A%5Cdev%5Cphoto.jpg';
$array['oauth_timestamp'] = '1291739697';
$array['oauth_token'] = '123456';
$array['tile'] = 'true';


That way is really easy to just unset($array['image']) and then implode() everything back. Any ideas on how to do that? Thanks!

Answer Source

Use parse_str() to take it apart, and http_build_query() to put it back together again.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download