note 35807 deleted from reserved.variables by sniper
| From: | sniper@php.net | Date: | Tue, 21 Oct 2003 19:42:25 +0000 |
| Subject: | note 35807 deleted from reserved.variables by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59058@lists.php.net to get a copy of this message | ||
Note Submitter: rsalazar@universia.net.mx
----
Yet another version of this function. I've been using this one and seems to work just fine.
It adds (if it doesn't exist) or replaces (if it exists) the $value of the $param on the $query
:) If $ceol (cleanEndOfLine) is evaluated as TRUE and the $param is found, anything after that will
be deleted don't ask, it was useful... once
<?php
function replaceOnQueryString( $query, $param, $value = NULL, $ceol = FALSE )
if( !is_null($value) && !preg_match('/(^|\?|&)'. $param .'=/i',
$query) )
return $query .($query ? '&' : ''). $param .'='. $value;
$pattern = '/(^|\?|&)('. $param .((bool)$ceol ? ')=.*$/i' :
')(=[^&]*)?/i');
return preg_replace($pattern, is_null($value) ? '' : '$1$2='. $value,
$query);
}
?>
I'm not sure if I'm keeping it simple or making difficult what already is simple, but here
you have anyway