On Thu, 27 Nov 2003, Eugene Lee wrote:
> Instead of using regexps on the URL, it might be easier (and safer) to
> loop through $_GET, build a new $geturl array, add/delete/change any
> variables in $geturl, then build a new $geturlstr string that can then
> be appended to your hyperlinks.
What about something like this:
$newvars = array("page2" => 3);
$urlstring = http_build_query(array_merge($_GET,$newvars));
It looks like http_build_query() is a pretty new feature so you could make
a basic replacement for it like so:
if (!function_exists("http_build_query")) {
function http_build_query($data) {
if (!is_array($data)) { return; }
foreach($data as $k => $v) { $r[] = "{$k}=".urlencode($v); }
return implode("&",$r); } }
Also, a way to filter the keys from the $_GET url may be useful here:
function key_filter($data,$allowed) {
foreach($data as $k => $v) {
if (in_array($k,$allowed)) { $r[$k] = $v; } } return $r; }
Putting it all together:
$allow_keys = array("action", "page", "custtype", "gender");
$new_vars = array("page" => 3, "action" => "newaction");
$urlstring = http_build_query(
array_merge( key_filter($_GET,$allow_keys),$new_vars) );
--
Kelly Hallman
// Ultrafancy
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php