note 51808 added to function.preg-replace

From: Date: Mon, 11 Apr 2005 21:13:42 +0000
Subject: note 51808 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-87861@lists.php.net to get a copy of this message
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" :) ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51808 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51808&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51808&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51808&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51808&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51808&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51808&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87861) next »