note 51808 deleted from function.preg-replace by didou

From: Date: Sun, 23 Apr 2006 22:52:31 +0000
Subject: note 51808 deleted from function.preg-replace by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-109232@lists.php.net to get a copy of this message
Note Submitter: greenthumb at 4point-webdesign dot com ---- I use the following function to eliminate parameters from a given querystring that i don't want in the qry by telling which ones are allowed: <?php function cleanqry($allow,$qry) { $allow=str_replace(',','|',$allow); $qry=preg_replace( '#([^\=&\?]+)(?<!'.$allow.')\=([^\=&]+)(&)?#', '', $qry); return $qry; } echo cleanqry('g1|g2|g3', 'g1=good&g4=bad&g2=good&g3=good&g5=bad'); /* output: g1=good&g2=good&g3=good& */ ?> maybe you have to check for lost "?" or "&", i left this out because i only want a function for the "core-problem" :)

« previous php.notes (#109232) next »