note 44922 deleted from function.http-build-query by aidan
| From: | aidan@php.net | Date: | Mon, 22 Nov 2004 04:22:36 +0000 |
| Subject: | note 44922 deleted from function.http-build-query by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-80845@lists.php.net to get a copy of this message | ||
Note Submitter: sebastian dot himberger at gmx dot de
----
Here's a simple function to edit parameters of a query String. perhaps you want to encode the
$value and $param variable, but i wanted this function to be as simple as possible.
Note: This function was not tested much, but i seems to work ;)
/* Sets a parameter in a query String */
function query_set_param($query, $param, $value) {
if (strlen($query) == 0) {
return $param.'='.$value;
}
if (preg_match('/&?'.$param.'=/', $query)) {
$pattern = '/(.*?'.(preg_quote($param)).'=).*?(&|$)/i';
$replacement = '\\1'.$value.'\\2';
return preg_replace($pattern, $replacement,$query);
}
return $query.'&'.$param.'='.$value;
}
/* Sets multiple parameters in a query String */
function query_set_params($query, $param_array) {
foreach ($param_array as $key => $value) {
$query = query_set_param($query, $key, $value);
}
return $query;
}